Spring JMS ActiveMq – How to implement a runtime SpringBoot ActiveMQ JmsResponse application

In the past post, we had learned how to build a SpringBoot application for handling ActiveMQ default destination by using @SendTo annotation. Can we compute the response destination at runtime? -> Yes, so with the tutorial, JavaSampleApproach will guide how to implement a SpringBoot ActiveMQ JmsResponse application with JmsResponse class.

Related posts:
ActiveMQ – How to create a SpringBoot ActiveMQ Response Management application by @SendTo annotation
Send Java object messages to ActiveMQ server (specially with Bi-Directional relationship Java objects)
Spring JMS ActiveMq Topic (Publisher-Subcribers pattern)

I. Technologies

– Java 8
– Maven 3.6.1
– Spring Tool Suite: Version 3.8.4.RELEASE
– Spring Boot: 1.5.4.RELEASE
– Apache ActiveMQ 5.14.0

II. Spring Boot ActiveMQ JmsResponse application

With the support of JmsResponse, we can configure the response destination at runtime:

SpringBoot ActiveMQ Response Management application - JmsResponse - architecture

III. Practice

In the tutorial, we create 2 SpringBoot projects {SpringActiveMqJmsResponse, SpringActiveMqProducerConsumer}:

SpringBoot ActiveMQ JmsResponse - JmsResponse - project structures

Step to do:
– Create SpringBoot projects
– Create model messages
– Configure ActiveMq ConnectionFactory
– Create Jms Producer/Listeners
– Run and check results

1. Create SpringBoot projects

Using SpringToolSuite, create 2 SpringBoot projects {SpringActiveMqJmsResponse, SpringActiveMqProducerConsumer}, then add dependencies:

2. Create model messages

Create 2 model classes {Company, Product}:

– Company:

– Product:

3. Configure ActiveMq ConnectionFactory

– Create ActiveMqConnectionFactoryConfig file:

4. Create Jms Producer/Listeners
4.1 For SpringActiveMqProducerConsumer project

– Create a Producer:

– Create a Consumer:

4.2 For SpringActiveMqJmsResponse project

– Create a JmsReplyConsumer:

5. Run and check results

– Start ActiveMQ server with commandline: C:\apache-activemq-5.14.5>.\bin\activemq start.
– Build and Run the SpringBoot applications {SpringActiveMqJmsResponse, SpringActiveMqProducerConsumer} by commandlines:
{mvn install -Dmaven.test.skip=true, mvn spring-boot:run}

-> Logs of JmsReplyConsumer from SpringActiveMqJmsResponse:

-> Logs of JmsConsumer from SpringActiveMqProducerConsumer:

-> With ActiveMQ server, go to http://localhost:8161/admin/queues.jsp:

SpringBoot ActivMQ Response Management application - JmsResponse - activemq status

IV. Sourcecode


By grokonez | July 25, 2017.

Related Posts

Got Something To Say:

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