How to use Spring JMS with ActiveMQ – JMS Consumer and JMS Producer | Spring Boot
Tags: springboot, springjms, jmsconsumer, jmsproducer
Published: 2021-05-06 12:47:45

https://grokonez.com/spring-framework/spring-boot/use-spring-jms-activemq-jms-consumer-jms-producer-spring-boot

How to use Spring JMS with ActiveMQ – JMS Consumer and JMS Producer | Spring Boot

<strong>Spring JMS</strong> (Java Message Service) is a powerful mechanism to integrate in distributed system.
<strong>ActiveMq </strong>is a Java Open Source, it is simple JMS solution for concurrent, consumers and producers architecture in integrated development.
The tutorial will guide you how to build a simple application with <strong>Spring JMS</strong>, <strong>ActiveMQ</strong>.

Related Articles:
- <a href="https://grokonez.com/spring-framework/spring-boot/apache-artemis-produceconsume-jms-messages-springboot-artemis-applications">Apache Artemis – How to produce/consume JMS messages with SpringBoot Artemis applications.</a>
- <a href="https://grokonez.com/spring-framework/spring-boot/activemq-create-springboot-activemq-response-management-application-sendto-annotation">ActiveMQ – How to create a SpringBoot ActiveMQ Response Management application by @SendTo annotation</a>
- <a href="https://grokonez.com/spring-framework/spring-boot/start-spring-apache-kafka-application-springboot">How to start Spring Apache Kafka Application with SpringBoot</a>
- <a href="https://grokonez.com/spring-framework/spring-boot/spring-jms-activemq-send-java-object-messages-activemq-server-specially-bi-directional-relationship-java-objects">Spring Jms ActiveMq – How to send Java object messages to ActiveMQ server (specially with Bi-Directional relationship Java objects)</a>
- <a href="https://grokonez.com/spring-framework/spring-boot/activemq-work-spring-jms-activemq-topic-publisher-subcribers-pattern-using-springboot">ActiveMq – How to work with Spring JMS ActiveMq Topic (Publisher-Subcribers pattern) using SpringBoot</a>

<!--more-->
<div id="tuttoc" class="jsa-toc"></div>
<div id="tutcontents">	 	<div id="tutcontents">
<h2>I. Technology</h2>
- Java 1.8
- Maven 3.3.9
- Spring Tool Suite – Version 3.8.1.RELEASE
- Spring Boot: 1.4.0.RELEASE
- ActiveMQ 5.14.0
- Docker 1.12.0
<h2>II. Overview</h2>
<h3>1. Goal</h3>
<img class="alignnone size-full wp-image-953" src="https://grokonez.com/wp-content/uploads/2016/09/springjms-activemq-goal.jpg" alt="springjms-activemq-goal" width="600" height="285" />
Our goal is to build an application that receives processing message request from <strong>REST Client</strong>, in our case, a browser, then use <strong>Spring JMS API</strong> with <strong>Jms Template</strong> for<strong> JMS Producer</strong> and <strong>JMS Customer</strong>, via <strong>Connection Factory</strong> to interact with <strong>ActiveMQ</strong> which is run by <strong>Docker</strong>, and return the response message to Client.
<h3>2. Project Structure</h3>
<img class="alignnone size-full wp-image-991" src="https://grokonez.com/wp-content/uploads/2016/09/springjms-activemq-project-structure.jpg" alt="springjms-activemq-project-structure" width="650" height="349" />
- <strong>application.properties</strong> to configure <strong>ConnectionFactory</strong>
- <strong>JmsProducer </strong>and <strong>JmsConsumer </strong>autowired <strong>JmsTemplate</strong>
- interface <strong>JmsClient</strong> with 2 methods: send and receive.
- implementation of <strong>JmsClient</strong> autowired <strong>JmsProducer</strong>, <strong>JmsConsumer</strong>, <strong>JmsClient</strong> should be autowired in <strong>WebController</strong> and will be used to implement method send/receive message.
- <strong>WebController</strong> is a <em>RestController</em> which has request mapping method for <em>RESTful</em> request, such as produce and receive.
- <strong>Dependencies</strong> for Spring Boot Web, JMS and ActiveMQ are added in <strong>pom.xml</strong>
<h3>3. Step to do</h3>
- Create Spring Boot project &amp; add Dependencies
- Set up <strong>ConnectionFactory</strong>
- Create <strong>JMS Consumer</strong> and <strong>JMS Producer</strong>
- Create <strong>JMS Client</strong>
- Create a <strong>Web Controller</strong>
- Run <strong>ActiveMQ</strong> by <strong>Docker</strong>
- Run Spring Boot Application &amp; Enjoy Result
<h3>4. Demo Video</h3>
<iframe width="560" height="315" src="https://www.youtube.com/embed/UA4gQFcCTzw" frameborder="0" allowfullscreen></iframe>

More at:

https://grokonez.com/spring-framework/spring-boot/use-spring-jms-activemq-jms-consumer-jms-producer-spring-boot

How to use Spring JMS with ActiveMQ – JMS Consumer and JMS Producer | Spring Boot