JMS Receiver application with ActiveMQ and Maven

We have been through the basic introduction to Java Messaging Service (JMS), we are now ready to create a simple JMS Receiver application, where a message will be dropped on a particular queue and a listener in our application will be consuming the message to further process it.

Make sure that the activeMQ setup is up and running before proceeding. Click here to know how this can be done.

Let’s first pickup a standard queue name to be used in our application for demonstration purpose. Let’s say it to be testQueue.

  1. The first step is to configure our application’s web.xml first –
  2. Add the dependencies into the pom.xml
  3. Let’s now create the listener class SimpleMessageListener.java
  4. Time to write create the jmsContext.xml

So our JMS receiver application is ready. Adding it to the application server and starting the same, starts listening to the testQueue for any arriving message.


Drop Message to the Queue through HAWTIO console

  1. Now login to the Hawtio console at http://localhost:8161/hawtio/ using the credentials admin/admin.
  2. Once you login to the Hawtio console, click on the Queue menu item from the left sidebar. Now create a queue named testQueue. Refer to the below snapshot – Create a sample JMS Queue
  3. Once the testQueue gets created, we could then see the queue listed under the Queue menu item. Refer to the below snapshot – Queue configuration through Hawtio
  4. Click on the newly created queue testQueue and click on the ‘Send’ menu item, which shows up a textarea to add any sample message. Note that in the below snapshot for the same, we have added any random message – ‘Hello jCombat!’ and click on the Send Message button.Send a sample message using Hawtio console

Note that the message sending mechanism that we used via Hawtio console is usually used for debugging purposes.

Now check out the server console and notice that the message that we had sent to the testQueue queue can be seen logged. Refer to the below snapshot –

Application server console to confirm the receipt of message by the receiver application

Receive our updates to your inbox

Get more stuff like this
in your inbox

Subscribe to our mailing list and get interesting stuff and updates to your email inbox.