题
我已经设置了一个排队配置在activemq.xml (说的版本5.2.0)中所描述的 文档.
<destinations>
<queue physicalName="FOO.BAR" />
<queue physicalName="DUMMY" />
</destinations>
我试图访问它从java(于同一主)与下列代码:
Hashtable properties = new Hashtable();
properties.put(Context.INITIAL_CONTEXT_FACTORY,
"org.apache.activemq.jndi.ActiveMQInitialContextFactory");
properties.put(Context.PROVIDER_URL, "tcp://localhost:61616");
context = new InitialContext(properties);
factory = (ConnectionFactory) context.lookup("ConnectionFactory");
connection = factory.createConnection();
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
queueName = "DUMMY"; // which can be either FOO.BAR or DUMMY
dest = (Destination) context.lookup(queueName);
我receveing的以下错误,虽然排队可以在jconsole(树/org.apache.说/排队):
javax.naming.NameNotFoundException: DUMMY
请告诉我我在做什么错误的。很多很多的感谢!
解决方案
首先,你不必在明确创建任何队列代理虽然它没有任何伤害。
另外,在经纪人提供的目的地不是自动奇迹般地使用某种JNDI名称映射到一个JNDI上下文你。
由于这里描述你可以做到这一点明确。如果你想JNDI的自动神奇人口再使用的JNDI命名约定的 dynamicQueues /假人的作为JNDI名称可以查找(如在的动态创建目的地的)
其他提示
嗯..很好,当我要听一个队列,我通常做这样的事情。 (从进口的javax.jms)
队列队列;
// Connect to ActiveMQ
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(messageBrokerURL);
connection = factory.createConnection();
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
// List to Dummy Queue
queue = session.createQueue("DUMMY");
messageConsumer = session.createConsumer(queue);
messageConsumer.setMessageListener(queueHandler);
// Start the connection
connection.start();
,并确保您的处理程序实现消息监听。
不隶属于 StackOverflow