11

I am getting this error when trying to create a ActiveMQ broker with the BrokerFactory:

java.io.IOException: Could not load failover factory:java.io.IOException: Could not find factory class for resource: META-INF/services/org/apache/activemq/broker/failover
    at org.apache.activemq.util.IOExceptionSupport.create(IOExceptionSupport.java:27)
    at org.apache.activemq.broker.BrokerFactory.createBrokerFactoryHandler(BrokerFactory.java:43)
    at org.apache.activemq.broker.BrokerFactory.createBroker(BrokerFactory.java:70)
    at org.apache.activemq.broker.BrokerFactory.createBroker(BrokerFactory.java:54)
    at ...
Caused by: java.io.IOException: Could not find factory class for resource: META-INF/services/org/apache/activemq/broker/failover
    at org.apache.activemq.util.FactoryFinder$StandaloneObjectFactory.loadProperties(FactoryFinder.java:96)
    at org.apache.activemq.util.FactoryFinder$StandaloneObjectFactory.create(FactoryFinder.java:58)
    at org.apache.activemq.util.FactoryFinder.newInstance(FactoryFinder.java:146)
    at org.apache.activemq.broker.BrokerFactory.createBrokerFactoryHandler(BrokerFactory.java:41)
    ... 5 more

It seems like pathing error or something similar, I just cant figure out the root cause.

This is the code causing it:

URI brokerUri = new URI(bean.getBrokerConfigUrl());
broker = BrokerFactory.createBroker(brokerUri);

Here is the url I am calling:

failover:(tcp://internalUrl.net:port#,tcp://internalUrl.net:port#)?randomize=false&timeout=30000&jms.redeliveryPolicy.maximumRedeliveries=-1&jms.prefetchPolicy.all=0

So is this likely a pathing error? Am I not including a required jar? Is the url not formatted properly? I'm lost here.

Edit: Added bounty

Tim
  • 189
  • 1
  • 14
  • How are you running this code? From standalone Java or in some container or what? Also always write the versions of the software you use, as that is important to know to be able to help. – Claus Ibsen Aug 07 '15 at 08:38
  • Sorry! I get this error both when run in eclipse and as a jar (generated by maven in eclipse). Using activemq 5.8. – Tim Aug 07 '15 at 13:08
  • Then its eclipse generating a jar that is the problem. The JAR must include some meta files that the released ActiveMQ jars contain. – Claus Ibsen Aug 07 '15 at 13:32
  • I just unpackaged the jar to check that, and while the meta files are there, they are not in META-INF/services/org/apache/activemq/broker/, like the error says the broker factory is looking for. Instead they are in META-INF/services/org/apache/activemq/transport/. Do you know why BrokerFacotry might be looking there? Ive searched far and wide but I cannot find a solution to this, or why it might be the case. – Tim Aug 07 '15 at 15:10
  • Hi Tim, that's a good find. I have the same issue and first didn't spot it, but the error claims .../activemq/transport/broker while the resource is only ../activemq/broker/broker - one fix would probably be to unzip, move resources around and rezip, but that's nasty. – Axel Podehl Aug 14 '17 at 16:54
  • I think I get it now: the broker URL "broker:.." is for org.apache.activemq.broker.BrokerFactory only. And that thing is not a JMS ConnectionFactory. If you have an ActiveMQInitialContextFactory and want to start an embedded broker, you must use the vm transport. For example: "vm:(broker:(tcp://localhost:61616)?persistent=false)" - see also http://activemq.apache.org/vm-transport-reference.html - it's all a bit too complicated, I think. – Axel Podehl Aug 14 '17 at 17:22

1 Answers1

3

This isn't a classpath or jar issue. According to the active MQ documentation the BrokerFactory only supports URIs for xbean, broker or properties and does not support a failover URI.

The following two documents should give you more information on setting up and configuring a broker factory.

http://activemq.apache.org/broker-configuration-uri.html

http://activemq.apache.org/how-do-i-embed-a-broker-inside-a-connection.html

Aestel
  • 409
  • 8
  • 12