Spring JMS and ActiveMQ Integration – point-to-point domain

This tutorial will show you how we can integrate Spring and Apache ActiveMQ using point-to-point messaging domain. For more information on point-to-point messaging system please read tutorial http://www.roytuts.com/configure-jms-client-using-glassfish-3/

Before you moving forward please read the tutorial http://www.roytuts.com/apache-activemq-configuration-in-windows/ for configuring ActiveMQ but do not create any Queue.

Now we will look into the following steps in order to implement point-to-point messaging system using Spring and ActiveMQ integration.

1. Create a class called MessageProducer that will produce message or send message to the destination – Queue.

 2. Create a class called MessageDefaultConsumer that will receive message from the destination – Queue.

 3. Create an XML property file that will hold all key/value pairs for the application. Put this file under src/main/resources

 4. Create an XML configuration file that will hold all JMS related configuration for the application. Put this file under src/main/resources/jms

 5. Create an XML file that will load all other resources and configure support for annotation in the application. Put this file under src/main/resources/spring

 6. Create a test class under src/test/java that will run the MessageProducer.

 

7. Run the MessageProducer.

Output

 

8. Click on Queues in ActiveMQ Web Console. You will not see any message in the IN_QUEUE because as soon as you ran the MessageProducer the message has been consumed by the MessageDefaultConsumer and now you will see one message has been dequeued. We do not need to run the MessageDefaultConsumer because it is an asynchronous messaging system and MessageDefaultConsumer is already registered to the Spring’s DefaultMessageListenerContainer. So when a message arrives to the Queue, the message gets automatically consumed by the consumer’s onMessage() method.

ActiveMQ SPring JMS integration

Here is the pom.xml

 

That’s all. Thank you for reading.

Soumitra

Software Professional, I am passionate to work on web/enterprise application. For more information please go to about me. You can follow on Twitter. You can be a friend on Facebook or Google Plus or Linkedin

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.