5 Programming and Configuring MDBs: Main Steps

This section provides step-by-step instructions for implementing an MDB. For a summary of key deployment elements for MDBs, see message-destination-descriptor Element of the weblogic-ejb-jar.xml File.

Required JMS Configuration

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

  • A JMS connection factory—one that supports XA, if your MDBs are transactional.

    The default WebLogic MDB connection factory is XA-capable. For information about the default connection factories, see "Using a Default Connection Factory" in Oracle Fusion Middleware Configuring and Managing JMS for Oracle WebLogic Server. For instructions to create a custom WebLogic JMS connection factory, see "Create connection factories in a system module" in Oracle Fusion Middleware Oracle WebLogic Server Administration Console Help.

    The default behavior and configuration methods for other JMS providers vary. If you use a non-Oracle JMS provider, see the vendor documentation for details.

  • A JMS destination

    For instructions on configuring WebLogic JMS destinations, see Oracle Fusion Middleware Oracle WebLogic Server Administration Console Help.


    If your JMS provider is a remote WebLogic Server JMS provider or a foreign JMS provider, and you use the wrapper approach recommended in Whether to Use Wrappers, in addition to configuring the non-local JMS components, you must also configure a Foreign Connection Factory and Foreign JMS Destination in your local JNDI tree.

Create MDB Class and Configure Deployment Elements

Follow these 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 uses to create an instance of the message-driven bean in the free pool.

    • 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.

  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. For instructions, see Configuring MDBs for Destinations.

  4. Compile and generate the MDB class using the instructions in Compile Java Source in Oracle Fusion Middleware Programming 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 Oracle Fusion Middleware 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.