Software Development, Spring, Spring Boot

Spring Boot – Embedded ActiveMQ

This post demonstrates how to embed an ActiveMQ instance in Spring Boot and produce/consume messages with a simple example.

Spring Boot Application

You may still use the Spring Initialzr which is fine but we need to update the generated pom.xml to include additional dependencies.

Our @Configuration class

We have two parts here – the embedded JMS server and client-stuff sections. @EnableJMS f is just an annotation that allows us to use @JmsListener (see MessageReceiver class).

Our Main class

In this class, we send a message to the JMS queue.

Sample Output

Download the Codes



Got comments or suggestions? We disabled the comments on this site to fight off spammers, but you can still contact us via our Facebook page!.

You Might Also Like


  1. 1

    i have requirement like when some event happens in one of the web servers, it will send message to the remaining web servers that are running behind the load balancer, how can i achieve with this? thanks in advance

  2. 2

    Apologies from the late response. Did you mean web servers or web applications? If web servers, then I’d imagine any changes to implement your requirements may be done through some configurations.

    If web applications, then we are generally talking about code changes.

  3. 3

    in production i have load balancer and multiple web applications running on the multiple tomcats, if some event happens in the one of the web application that is running on the web server, then it should be notified to the other same web application running on the different web server, if you an idea how we can achieve this with spring embedded mq , please let me know.


  4. 4

    From the top of my head, I think embedded MQ might not work as it is only available to one of the web applications. A remote MQ may be a solution as all web applications can push to and receive events from a common queue or topic. I’d imagine you won’t need any load-balancing for events.

Comments are closed.