Browse DevX
Sign up for e-mail newsletters from DevX


EJB Messaging, Part II: Message-Driven Beans-2 : Page 2


MDBs: EJB and JMS Interfaces in One
Message-Driven Beans do not follow the typical pattern for EJB interface implementation, because an MDB is a cross between a stateless session EJB and a JMS client. Rather than defining EJB component interfaces, MDBs implement two interfaces: one is an EJB interface and the other is a JMS interface. The following code is a sample of an MDB class signature:

public class MessageBean implements MessageDrivenBean, 

The first interface, javax.ejb.MessageDrivenBean, is the bean's interface to the container. It allows the EJB container to manage the MDB, just as the container manages session and entity beans. The second interface, javax.jms.MessageListener, allows the bean to register with a JMS-enabled MOM (messaging-oriented middleware) server as a JMS listener.

As full-fledged JMS clients, MDBs can both send and receive messages asynchronously via a MOM server. As enterprise beans, MDBs are managed by the container and declaratively configured by an EJB deployment descriptor:


All of these element names should look familiar except for two:

  • <message-driven> This element represents the bean type. It is a direct parallel for the elements <session> and <entity>.
  • <message-driven-destination> This element indicates the JMS destination type (topic or queue) to which the MDB will bind.

  • Thanks for your registration, follow us on our social networks to keep up-to-date