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.

This was last published in October 2004

Dig Deeper on Microservices pattern, platforms and frameworks



Find more PRO+ content and other member only offers, here.

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.