Message-Driven POJOs

Receiving messages asynchronously means you have a nonblocking process that is listening for messages on a particular queue or topic. This technique is a form of event-driven processing where the presence of a message triggers an action on a message listener. Message-driven beans (discussed in Chapter 8) are Java EE’s answer to asynchronous receivers. The Spring Framework also supports asynchronous receivers through MDPs.

There are three different ways of configuring asynchronous message listeners in Spring: implementing the javax.jms.MessageListener interface, implementing Spring’s SessionAwareMessageListener, and finally, wrapping a standard POJO in Spring’s MessageListenerAdapter class. These three methods vary in terms of how the message listener class is structured. All three of these methods use a message listener container, which is analogous to the JmsTemplate class described in the previous sections. The following sections will describe the details of the message listener container and each of the three message-driven bean techniques.

The Spring Message Listener Container

Message-driven POJOs are created within the context of a message listener container. The message listener container binds the connection factory, JMS destination, JNDI destination resolver (if using JNDI), and the message listener bean. Spring provides two message listener containers: the DefaultMessageListenerContainer and the SimpleMessageListenerContainer. While both of these message ...

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.