Message-Driven Beans
Message-driven beans are quite similar to stateless session beans. Both are stateless, and with each method call, the container establishes a transaction context based on the deployment-descriptor transaction attribute for the message-listener methods.
Message-driven beans implement the MessageDrivenBean interface for lifecycle callbacks and a message-listener
interface for business methods that is specific to the type of message
provider with which the bean is used. Message-driven beans used with the
JMS MessageListener interface have
only one business method, onMessage(
), that takes one parameter: an instance of javax.jms.Message. Those that are used with
another message provider must implement all of the methods of the
corresponding message-listener interface. The interaction with JDO is
the same in all cases.
The lifecycle of a message-driven bean (shown in Figure 17-3) is as simple as a
stateless session bean. To use JDO with message-driven beans, your
application uses the setMessageDrivenContext(
) method to save the context and look up and save the
PersistenceManagerFactory.

Figure 17-3. The lifecycle of a message-driven bean
To process the message-listener method, your application code
obtains a PersistenceManager from the
PersistenceManagerFactory and handles the message, performing JDO accesses as required. At the end of the business method, you close ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access