JMS Sender application with ActiveMQ and Maven

We have already seen how to create a JMS Receiver application with ActiveMQ and Maven. Let’s check out how we can similarly create the JMS Sender application.

web.xml remains the same as we had used for creating the receiver application –

jmsContext.xml would change a bit to something like –

Note that we have added two new beans for jmsTemplate and messageSender class, which will be using the jmsTemplate instance to send message to the destination queue.

Now let’s create a message sender class, which will actually be sending the message –

Almost done. Now let’s create the client class, which will get the simpleMessageSender bean from jmsContext and send some message string by calling it’s sendMessage method, thus dropping the message to the configured queue testQueue (as seen highlighted in the jmsContext file content shown above).

Now run the TestClient class as Java Application.

Verify message on the destination queue

To verify that the message that we have sent through our client class has successfully arrived at the destination queue i.e. testQueue, login to the Hawtio console and from the queues listed on the left, click on the testQueue link, which shows up the testQueue details on the main content area as can be seen below – Check messages on destination queue - jCombat

Now click on the Message that could be seen listed under the ‘Browse’ tab. We could see the same message that we had sent pops out as –Verify message on the JMS queue - jCombat

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.