Chapter 9. Spring and JMS

The Spring Framework provides built-in support for JMS that greatly simplifies the development of messaging-based applications. For synchronous message sending and receiving, Spring provides a JMS template that abstracts the developer from the details of the JMS API. For asynchronous message receiving, Spring provides a framework that allows regular POJOs to act as asynchronous message listeners (also known as message-driven POJOs, or MDPs). Message-driven POJOs are similar in nature to the message-driven beans discussed in the previous chapter. However, unlike message-driven beans, MDPs can be created using standard POJO business objects that optionally have no knowledge of messaging or JMS.

This chapter introduces JMS messaging using version 2.5 of the Spring Framework. We will start by reviewing the overall architecture and components of Spring’s messaging framework, and then describe the details of connecting to a JMS provider, sending messages, receiving messages synchronously, and creating message-driven POJOs to receive messages asynchronously. In the last section (The Spring JMS Namespace), we will discuss the new Spring JMS namespace, which simplifies the configuration for Spring-based JMS containers and listeners.

Spring Messaging Architecture

The JMS template and the message listener container are the two main components within the Spring Framework for using JMS messaging. Spring’s JMS template (JmsTemplate) is used when sending messages or receiving ...

Get Java Message Service, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.