What Is a Message-Driven Bean?
A message-driven bean is an enterprise bean that allows Java EE applications to process messages asynchronously. This type of bean normally acts as a JMS message listener, which is similar to an event listener but receives JMS messages instead of events. The messages can be sent by any Java EE component (an application client, another enterprise bean, or a web component) or by a JMS application or system that does not use Java EE technology. Message-driven beans can process JMS messages or other kinds of messages.
The following topics are addressed here:
What Makes Message-Driven Beans Different from Session Beans?
The most visible difference between message-driven beans and session beans is that clients do not access message-driven beans through interfaces. Interfaces are described in the section Accessing Enterprise Beans. Unlike a session bean, a message-driven bean has only a bean class.
In several respects, a message-driven bean resembles a stateless session bean.
The instance variables of the message-driven bean instance can contain some state across the handling of client messages, such as a JMS API connection, an open database connection, or an object reference to an enterprise bean object.
Client components do not locate message-driven beans and invoke methods
directly on them. Instead, a client accesses a message-driven bean
through, for example, JMS by sending messages to the message destination
for which the message-driven bean class is the
Message-driven beans have the following characteristics.
When a message arrives, the container calls the message-driven bean’s
A message can be delivered to a message-driven bean within a transaction
context, so all operations within the
When to Use Message-Driven Beans
Session beans allow you to send JMS messages and to receive them synchronously but not asynchronously. To avoid tying up server resources, do not to use blocking synchronous receives in a server-side component; in general, JMS messages should not be sent or received synchronously. To receive messages asynchronously, use a message-driven bean.