JMS Application with Spring Boot

Spring provides a JMS Integration framework that simplifies the use of JMS API.

The key class provided by Spring is JmsTemplate : JmsTemplate class handles the creation and releasing of resources when sending or synchronously receiving messages. Starting with Spring 4.1, JmsMessagingTemplate is built on top of JmsTemplate which provides an integration with the messaging abstraction, i.e., org.springframework.messaging.Message. This, in turn, allows to create a message to send in generic manner.

In order to connect and be able to send/receive messages, a ConnectionFactory must be configured. ConnectionFactory is one of the JMS administered objects which are preconfigured by an administrator. A client with the help of the configuration will make the connection with a JMS provider.

Spring provides two types of ConnectionFactory :

  • SingleConnectionFactory : is an implementation of ConnectionFactory interface, that will return the same connection on all createConnection() calls and ignore calls to close()
  • CachingConnectionFactory : extends the functionality of the SingleConnectionFactory and adds enhances it with a caching of Sessions, MessageProducers and MessageConsumers

Also, Message Listener Container must be configured.

Let’s see it in an example. It is a Maven Spring Boot JMS application which sends messages to ArtemisMQ JMS Server (more about building an application with spring boot – here). Here is final pom.xml file :

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







Leave a Reply

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