ActiveMQ: queue lookup problem

I configured the queue by setting it up in activeemq.xml (ActiveMQ version 5.2.0), as described in the documentation .

<destinations> <queue physicalName="FOO.BAR" /> <queue physicalName="DUMMY" /> </destinations> 

I am trying to access it from java (on the same host) with the following code:

 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); 

I get the following error, although the queue is visible in jconsole (Tree / org.apache.activemq / Queue):

 javax.naming.NameNotFoundException: DUMMY 

Please tell me what I'm doing wrong. Thank you so much!

+6
java jms activemq
source share
2 answers

Firstly, you do not need to explicitly create any queues in the broker , although this does no harm.

Also, destinations available in brokers are not automatically displayed in the context of JNDI, since you are using some kind of JNDI name.

You can do this explicitly, as described here . If you need a JNDI auto-magic population, then use the JNDI dynamicQueues / DUMMY naming convention as the JNDI name you are looking for (as described in Dynamically creating destinations )

+8
source share

Hmm .. well, when I want to listen to a lineup, I usually do something like this. (Import from javax.jms)

Queue queue;

  // 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(); 

And make sure your handler implements MessageListener.

0
source share

All Articles