我试图运行以下代码:
EmbeddedActiveMQ server = new EmbeddedActiveMQ();
server.setConfiguration(new ConfigurationImpl()
.setAcceptorConfigurations(singleton(new TransportConfiguration(
InVMAcceptorFactory.class.getName())))
.setPersistenceEnabled(false)
.setSecurityEnabled(false));
server.start();
ConnectionFactory cf = new ActiveMQConnectionFactory("vm://0");
Connection connection = cf.createConnection();
但是我有这个例外:
javax.jms.JMSException: Could not create Transport. Reason: java.io.IOException: Transport scheme NOT recognized: [vm]
at org.apache.activemq.util.JMSExceptionSupport.create(JMSExceptionSupport.java:36)
at org.apache.activemq.ActiveMQConnectionFactory.createTransport(ActiveMQConnectionFactory.java:333)
at org.apache.activemq.ActiveMQConnectionFactory.createActiveMQConnection(ActiveMQConnectionFactory.java:346)
at org.apache.activemq.ActiveMQConnectionFactory.createActiveMQConnection(ActiveMQConnectionFactory.java:304)
at org.apache.activemq.ActiveMQConnectionFactory.createConnection(ActiveMQConnectionFactory.java:244)
at com.hazelcast.jet.examples.jms.JmsTopicSample.main(JmsTopicSample.java:84)
Caused by: java.io.IOException: Transport scheme NOT recognized: [vm]
at org.apache.activemq.util.IOExceptionSupport.create(IOExceptionSupport.java:28)
at org.apache.activemq.transport.TransportFactory.findTransportFactory(TransportFactory.java:185)
at org.apache.activemq.transport.TransportFactory.connect(TransportFactory.java:64)
at org.apache.activemq.ActiveMQConnectionFactory.createTransport(ActiveMQConnectionFactory.java:331)
... 4 more
Caused by: java.io.IOException: Could not find factory class for resource: META-INF/services/org/apache/activemq/transport/vm
at org.apache.activemq.util.FactoryFinder$StandaloneObjectFactory.loadProperties(FactoryFinder.java:98)
at org.apache.activemq.util.FactoryFinder$StandaloneObjectFactory.create(FactoryFinder.java:60)
at org.apache.activemq.util.FactoryFinder.newInstance(FactoryFinder.java:148)
at org.apache.activemq.transport.TransportFactory.findTransportFactory(TransportFactory.java:182)
... 6 more
我在网上可以找到的所有信息都表明我缺少对类路径的依赖,但是没有一个因vm
协议而失败。
答案 0 :(得分:0)
原来,我使用了错误的导入。我用过:
org.apache.activemq.ActiveMQConnectionFactory
但我应该使用过:
org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory
出于某种原因,apache-artemis:2.10.1
包括对activemq版本5中activemq-client
的依赖,其中包括另一个类。
答案 1 :(得分:0)
如果您遇到此错误并且未使用 Apache Artemis,请确保 activemq-broker
位于类路径中。