ActiveMQ Producer/Consumer + SpringBoot RestAPIs example

In the tutorial, we show how to build SpringBoot RestAPIs to produce/consume data from ActiveMQ.

Related posts:
Spring Jms ActiveMq – How to send Java object messages to ActiveMQ server (specially with Bi-Directional relationship Java objects)
How to use Spring JMS with ActiveMQ – JMS Consumer and JMS Producer | Spring Boot
ActiveMq – Explicitly configure Spring ActiveMq ConnectionFactory with SpringBoot
ActiveMq – How to work with Spring JMS ActiveMq Topic (Publisher-Subcribers pattern) using SpringBoot

Technologies

  • Java 1.8
  • Maven 3.3.9
  • Spring Tool Suite – Version 3.9.4.RELEASE
  • Spring Boot: 2.0.3.RELEASE
  • ActiveMQ

Practice

We create a Spring JMS ActiveMQ with JMS Producer & JMS Consumer as below:

spring-activemq-java-object-message-architecture-ws

Then expose RestAPIs to POST/GET data to/from ActiveMQ:

  • @PostMapping(value="/api/customer")
  • @GetMapping(value="/api/customers")
Setup SpringBoot project

Use SpringToolSuite to create a SpringBoot project with below dependencies:

ActiveMQ Connection Factory

ActiveMqConnectionFactoryConfig ->

Add ActiveMQ configuration in application.properties ->

Data Model

– Create Customer model ->

– Create MessageStorage to storage Customer list ->

Create a bean for MessageStorage ->

JMS Producer

JmsProducer send messages to ActiveMQ:

JMS Consumer

JmsConsumer recieves messages from ActiveMQ ->

Rest APIs

RestAPIs ->

Run & Check Results

– Build & Run SpringBoot project with commandlines {mvn clean install, mvn spring-boot:run}.

-> Post Messages to ActiveMQ:

spring-boot-rest-api-activemq-producer-consumer + post-customer

spring-boot-rest-api-activemq-producer-consumer + post-customer-2

-> Get Messages:

spring-boot-rest-api-activemq-producer-consumer + get-all-customers

-> ActiveMQ state:

spring-boot-rest-api-activemq-producer-consumer + activemq

SourceCode

SpringBootActiveMQ

By grokonez | August 12, 2018.



Related Posts


Got Something To Say:

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

*