Embedded JMS Server Example

This examples shows how to setup and run an embedded JMS server using ActiveMQ along with ActiveMQ configuration files.

Example step-by-step

To run the example, simply type mvn verify from this directory

  1. Create ActiveMQ core configuration files and make sure they are within your classpath. By default, ActiveMQ expects the classnames to be "activemq-configuration.xml", "activemq-jms.xml", and "activemq-users.xml".
  2. Create and start ActiveMQ JMS server
  3.             EmbeddedJMS jmsServer = new EmbeddedJMS();
                jmsServer.start();
             

    At this point the JMS server is started and any JMS clients can look up JMS resources from the JNDI to send/receive messages from the server. To keep the example simple, we will send and receive a JMS message from the same JVM used to run the JMS server.

  4. Lookup JMS resources defined in the configuration
  5.             ConnectionFactory cf = (ConnectionFactory)context.lookup("/cf");
                Queue queue = (Queue)context.lookup("/queue/queue1");
             
  6. Send and receive a message using JMS API
  7. See the Queue Example for detailed steps to send and receive a JMS message

    Finally, we stop the JMS server and its associated resources.

  8. Stop the JMS server
  9.             jmsServer.stop();
             
  10. Stop the JNDI server
  11.             naming.stop();
                jndiServer.stop();