ActiveMQ is the default JMS provider in Apache Geronimo.

ActiveMQ can be used both as JMS Client and a JMS Broker. This short
article explains how to use it on a standalone client to access the
topics/queues setup on a remote Geronimo/ActiveMQ broker.

1) Setup the queues and topics on the ActiveMQ Broker
If you're using a standalone ActiveMQ broker, then following the instructions on
ActiveMQ's website should be enough to setup everything.
However, if your ActiveMQ's instance is embedded inside the J2EE Geronimo
Application Server, creating Queues and Topics is about deploying Resource
Adapters to your Geronimo server.
The following deployment descriptor can be used to deploy two topics and a
ConnectionFactory: weatherTopic and weatherRequestsTopic

Then deploy it using Geronimo's deploy tool :

The geronimo.log file should now refer to these newly deployed Topics.

2) Now that the queues are available server-side, what we want is access them
thanks to a standalone Client.
Usually, the process is the following one :

  • Contact the J2EE naming server (port 1099, RMI) to get an JNDI InitialContext.
  • The J2EE server automatically exposes the ConnectionFactory and the Topics
    through JNDI, so the InitialContext allows you to retrieve both the
    ConnectionFactory and the Topics
  • Once you have your Topics, you just use them..

However, ActiveMQ's JNDI Implementation does NOT talk to the naming server. It's
a stripped down version of a JNDI client that just allows to get Topics and
Queues directly from a JMS instance.
So, instead of supplying the naming server address, you have to supply the JMS
server address.
Most JNDI implementations use the java.naming.provider.url property to specify
the naming server's address. ActiveMQ uses the brokerURL one. Using the
java.naming.provider.url one instead will result in ActiveMQ trying to load the
whole Broker.

3) So, now we have explained the process, let's detail the Spring way of doing
things :

  • Create a file that's available in your classpath


  • Now, in your Spring description file, declare the bean that will read
    the properties from the file
  • Create a JNDI template (A Spring-specific wrapper around the JNDI InitialContext
  • Retrieve the ConnectionFactory from the JNDI context

I'm not 100% sure, but I think that you can put any Factory Name, it will just
work. (In a scenario where the JNDI context actually contacts a naming server,
it should match the name of the deployed ConnectionFactory)

  • Get the Topics instances from the JNDI Context
  • Now, you can reuse these Topics beans the way you want.
© 2004-2011 The Apache Software Foundation.
Apache ActiveMQ, ActiveMQ, Apache, the Apache feather logo, and the Apache ActiveMQ project logo are trademarks of The Apache Software Foundation. All other marks mentioned may be trademarks or registered trademarks of their respective owners.
Graphic Design By Hiram