Skip Headers
Oracle® Containers for J2EE Enterprise JavaBeans Developer's Guide
10g (10.1.3.5.0)

Part Number E13981-01
Go to Documentation Home
Home
Go to Book List
Book List
Go to Table of Contents
Contents
Go to Index
Index
Go to Feedback page
Contact Us

Go to previous page
Previous
Go to next page
Next
View PDF

Implementing an EJB 3.0 MDB

EJB 3.0 greatly simplifies the development of enterprise beans, removing many complex development tasks. For example:

For more information, see "What is a Message-Driven Bean?".

Note:

You can download an EJB 3.0 message-driven bean code example from: http://www.oracle.com/technology/tech/java/oc4j/10131/how_to/how-to-ejb30-mdb/doc/how-to-ejb30-mdb.html.

To implement an EJB 3.0 message-driven bean, do the following:

  1. Configure your message service provider.

    For more information, see the following:

  2. Create the message-driven bean class.

    You can create a POJO and define it as a message-driven bean with the @MessageDriven annotation.

    Note:

    OC4J ignores the @MessageDriven attribute mappedName.
  3. Configure message service provider information as follows:

    You can define this information with the @ActivationConfigProperty annotation.

    For more information, see the following:

  4. Add a data member for the MessageDrivenContext.

    You can use resource injection to easily initialize this data member without getter and setter methods.

  5. Implement the appropriate message listener interface as follows:

    For a JMS message-driven bean, implement the javax.jms.MessageListener interface to provide the onMessages method with the following signature:

    public void onMessage(javax.jms.Message message)
    

    This method processes the incoming message. Most MDBs receive messages from a queue or a topic, then invoke an entity bean to process the request contained within the message.

    In this method, you can use the MessageDrivenContext to acquire and configure a javax.ejb.TimerService if you implemented the TimedObject interface (see step 6).

  6. Optionally, implement the javax.ejb.TimedObject interface.

    Implement the ejbTimeout method with the following signature:

    public void ejbTimeout(javax.ejb.Timer timer)
    
  7. Optionally, define life cycle callback methods using the appropriate annotations.

    You do not need to define life cycle methods: OC4J provides an implementation for all such methods. Define a method of your message-driven bean class as a life cycle callback method only if you want to take some action of your own at a particular point in the message-driven bean's life cycle.

    For more information, see "Configuring a Life Cycle Callback Interceptor Method on an EJB 3.0 MDB".

  8. Optionally, define OC4J-proprietary deployment options.

    In an EJB 3.0 application, you can do this by annotating your message-driven bean class with the OC4J-proprietary oracle.j2ee.ejb.@MessageDrivenDeployment annotation (see "Configuring OC4J-Proprietary Deployment Options on an EJB 3.0 MDB").

  9. Complete the configuration of your message-driven bean (see "Using an EJB 3.0 Message-Driven Bean").