Home

 

Message-driven EJBs (MDBs)

MDBs were introduced into EJB 2.0 and have been extended in EJB 2.1, and simplified in EJB 3.0. MDBs are designed to consume incoming messages sent from a destination or endpoint system the MDB is configured to listen to. From the point of view of the message-producing client, it is impossible to tell how the message is being processed-whether by a stand-alone Java application, a MDB, or a message-consuming application implemented in some other language. This is one of the advantages of using messaging systems; the message-producing client is very well decoupled from the message consumer (similar to Web services in this respect).

From a development point of view, MDBs are the simplest type of EJB, because they do not have clients in the same sense as session and entity beans. The only way of invoking an MDB is to send a message to the endpoint or destination that the MDB is listening to. In EJB 2.0, MDBs only dealt with JMS messages, but in EJB | .1 this is extended to other messaging systems. The development of an MDB is different depending on the messaging system being targeted, but most MDBs are still designed to consume messages through JMS, which requires the bean class to implement the javax.jms.MessageListener interface, as well as javax.ejb.MessageDrivenBean.

A common pattern in this area is the message facade pattern, as described in EJB Design Patterns: Advanced Patterns, Processes and Idioms by Marinescu. This book is available for download from:

http://theServerside.com/articles/

According to this pattern, the MDB simply acts as an adapter, receiving and parsing the message, then invoking the business logic to process the message using the session bean layer.

ibm.com/redbooks