Java Reference
In-Depth Information
fast rules dictating the choice of message type. Explore all of the choices before making a
decision for your application.
We just finished reviewing most of the major parts of JMS, including how to send a mes-
sage, parts of a message, and the different types of messages. Full coverage of JMS is un-
fortunately beyond the scope of this chapter and book. To further explore JMS, visit ht-
tp://docs.oracle.com/javaee/7/tutorial/doc/partmessaging.htm . Having taken a closer look
at JMS messages, the time is right for us to look at Turtle's server message consumer.
4.3. Working with MDBs
We'll now explore MDBs in more detail. First, we'll examine the reasons for considering
them and then dive into how to use MDBs. We'll also discuss some best practices as well
as pitfalls to avoid when developing with MDBs.
MDBs are EJB components designed to consume asynchronous messages. Although
MDBs are intended to handle many different kinds of messages (see the sidebar “ JCA con-
nectors and messaging ), we'll primarily focus on MDBs that process JMS messages be-
cause that's what MDBs are most commonly used for. You might ask why you'd need to
employ EJBs to handle the task of consuming messages at all or why you need to use
JMS messaging in the first place. We'll address this question next. You'll develop a simple
message consumer application using MDBs and we'll show you how to use the @Mes-
sageDriven annotation. You'll also learn more about the MessageListener inter-
face, activation configuration properties, and the MDB lifecycle.
JCA connectors and messaging
Although JMS is by far the primary messaging provider for MDBs, as of EJB 2.1 it's not
the only one. Thanks to the Java EE Connector Architecture (JCA), MDBs can receive
messages from any Enterprise information system (EIS), such as PeopleSoft or Oracle
Manufacturing, not just MOMs that support JMS.
Suppose you have a legacy application that needs to send messages to an MDB. You can
do this by implementing a JCA-compliant adapter/connector that includes support for mes-
sage inflow contract . Once your JCA resource adapter or connector is deployed to a Java
 
Search WWH ::




Custom Search