Problem solve Get help with specific problems with your technologies, process and projects.

How do I use message-driven bean (MDB)?, part 1

How do I use message-driven bean(MDB)?
An increasingly important requirement of J2EE application systems is their ability to handle asynchronous messages passed from message-oriented middleware (MOM) systems. Java provides the Java Message Service (JMS) for handling MOM messages.

JMS is an application programming interface (API) abstraction of common concepts found in all MOM systems. JMS does not define wire protocols or message-content formats.

The single parameter to the onMessage (Message msg) method is of type javax.jms.Message and it is up to the MDB programmer to cast the Message object to one of the five JMS message types: TextMessage, ObjectMessage, MapMessage, BytesMessage and StreamMessage.

You can create your own asynchronous, JMS-enabled, message listener/receiver and make calls to a service-logic object from its onMessage callback, as in the following example:

public class MyJMSReceiver implements MessageListener

  public MyJMSReceiver()
    // initialize JMS topic/queue connection here

  public void onMessage(Message msg)
    // Message received
    BusinessService busService = unmarshalMessage(msg);
    Document response = busService.execute();

  private BusinessService unmarshalMessage(Message msg)
    // perform message-to-service conversion here
    return aBusinessServiceInstance;

Continued in part 2.

Dig Deeper on Topics Archive

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.