Skip Headers
Oracle® Fusion Middleware Programming Message-Driven Beans for Oracle WebLogic Server
11g Release 1 (10.3.6)

Part Number E15493-05
Go to Documentation Home
Go to Book List
Book List
Go to Table of Contents
Go to Master Index
Master Index
Go to Feedback page
Contact Us

Go to previous page
Go to next page
PDF · Mobi · ePub

5 Programming and Configuring MDBs: Main Steps

This section provides step-by-step instructions for implementing an MDB using pre-EJB 3.0 style XML descriptors to configure its behavior. For an EJB 3.0 annotation sample, see Topic MDB Sample..

For a summary of key deployment elements for MDBs, see Chapter 11, "Deployment Elements and Annotations for MDBs." For an introduction to key deployment elements for topic MDBs, see Chapter 10, "Configuring and Deploying MDBs Using JMS Topics."

This chapter contains the following sections:

Required JMS Configuration

The steps in the following section assume that you have access to the appropriate JMS components:

Create MDB Class and Configure Deployment Elements

Use the following steps to implement a message-driven bean:

  1. Create a source file (message-driven bean class) that implements both the javax.ejb.MessageDrivenBean and javax.jms.MessageListener interfaces.

    The MDB class must define the following methods:

    • One ejbCreate() method that the container invokes after creating each new instance of the MDB.

    • One onMessage() method that is called by the EJB container when a message is received. This method contains the business logic that processes the message.

    • One setMessageDrivenContext{} method that provides information to the bean instance about its environment (certain deployment descriptor values); the MDB also uses the context to access container services. See Using the Message-Driven Bean Context,.

    • One ejbRemove() method that removes the message-driven bean instance from the free pool.


    Most EJB 3.0 applications implement only javax.jms.MessageListener, which defines a single method - onMessage().
  2. Declare the MDB in ejb-jar.xml, as illustrated in the excerpt below:


    The key behaviors to configure are:

  3. Configure WebLogic-specific behaviors for the MDB in the message-driven-descriptor element of weblogic-ejb-jar.xml. For example:


    The key elements to configure are those that specify how to access the destination. In general, applications that follow best practices should never need to specify the initial-context-factory or provider-url fields. For instructions, see Configuring MDBs for Destinations.

  4. Compile and generate the MDB class using the instructions in "Compile Java Source" in Programming WebLogic Enterprise JavaBeans for Oracle WebLogic Server.

  5. Deploy the bean on WebLogic Server using the instructions in the section "Preparing Applications and Modules for Deployment" in Deploying Applications to Oracle WebLogic Server

    If WebLogic Server cannot find an MDB's JMS destination during deployment, deployment succeeds, but WebLogic Server prints a message saying the destination was not found. The MDB bean then periodically tries to connect to its JMS queue until it succeeds. For more information, see Migration and Recovery for Clustered MDBs.