In this tutorials, we are going to see how we can use Spring Boot Apache ActiveMQ. Spring Boot internally provides an in-memory activemq starter to dealing with JMS messages.

Spring Boot Apache ActiveMQ In Memory:

As part of this example, I am going to create a producer and consumer programs, the producer can produce the message, as soon as the producer produces a message consumer will consume the message.


  • Spring Boot 2.0.5
  • ActiveMQ
  • Java8

Application Structure:

Spring Boot ActiveMQ Inmemory Example

Project Dependencies:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="" xmlns:xsi=""


  <description>Spring Boot ActiveMq In Memory Example</description>

    <relativePath/> <!-- lookup parent from repository -->



Spring ActiveMQ properties – Enabling spring in-memory ActiveMQ.

Creating Producer as rest controller.

Providing rest endpoint /publish to send messages to JMS queue using JmsTemplate.
package com.onlinetutorialspoint.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.jms.Queue;

public class Producer {

    private Queue queue;

    private JmsTemplate jmsTemplate;

    public String publish(@PathVariable("msg") final String msg){
        return "Your message <b>"+msg+"</b> published successfully";

JMS Configuration – Creating ActiveMQQueue and giving queue name as simple-jms-queue
package com.onlinetutorialspoint.config;

import org.apache.activemq.command.ActiveMQQueue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jms.annotation.EnableJms;

import javax.jms.Queue;
import java.awt.*;

public class JMSConfig {
    public Queue queue(){
        return new ActiveMQQueue("simple-jms-queue");

Creating Consumer.

Creating JmsListener and add this listener to above-created simple-jms-queue. It keeps listens to the simple-jms-queue, as soon as this queue get updated the listener will notify.
package com.onlinetutorialspoint.listener;

import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Component;

public class Consumer {

    @JmsListener(destination = "simple-jms-queue")
    public void listener(String msg){
        System.out.println("Received Message : "+msg);

Main class
package com.onlinetutorialspoint;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

public class SpringBootActiveMqInMemoryExampleApplication {

  public static void main(String[] args) {, args);

Run it.


mvn spring-boot:run
  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 :: Spring Boot ::        (v2.0.6.RELEASE)

2018-10-28 21:52:11.003  INFO 13024 --- [           main] ngBootActiveMqInMemoryExampleApplication : Starting SpringBootActiveMqInMemoryExampleApplication on DESKTOP-RN4SMHT with PID 13024 (E:\work\SpringBoot-ActiveMQ-InMemory-Example\target\classes started by Lenovo in E:\work\SpringBoot-ActiveMQ-InMemory-Example)
2018-10-28 21:52:11.038  INFO 13024 --- [           main] ngBootActiveMqInMemoryExampleApplication : No active profile set, falling back to default profiles: default
2018-10-28 21:52:11.256  INFO 13024 --- [           main] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.ser[email protected]6f15d60e: startup date [Sun Oct 28 21:52:11 IST 2018]; root of context hierarchy

Access the application and send any message.

Spring Boot ActiveMQ Inmemory Example 2

Message get published successfully, then we can check for application logs to confirm whether the consumer consumed the message or not.

Spring Boot ActiveMQ Inmemory Example 3

Yes, we can see the received message from the consumer. This is how we can use the Spring Boot in memory ActiveMQ.


Apache ActiveMQ

Happy Learning 🙂

Download Example

About the Author:

Founder of Love Java, Python, Shell and opensource frameworks. Follow him on twitter and facebook for latest updates.

Leave A Comment