Skip Headers
Oracle® Containers for J2EE Enterprise JavaBeans Developer's Guide
10g Release 3 (10.1.3)
B14428-02
  Go To Documentation Library
Home
Go To Product List
Solution Area
Go To Table Of Contents
Contents
Go To Index
Index

Previous
Previous
 
Next
Next
 

9 Implementing an EJB 3.0 MDB

This chapter explains how to implement an EJB 3.0 message-driven bean.


Note:

In this release, OC4J supports a subset of the functionality specified in the EJB 3.0 public review draft. You may need to make code changes to your EJB 3.0 OC4J application after the EJB 3.0 specification is finalized and OC4J is updated to full EJB 3.0 compliance. For more information, see "Understanding EJB Support in OC4J".

There are no OC4J-proprietary EJB 3.0 annotations. For all OC4J-specific configuration, you must still use the EJB 2.1 orion-ejb-jar.xml file.


For more information, see:

Implementing an EJB 3.0 MDB

EJB 3.0 greatly simplifies the development of EJBs, 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/ejb3/howtos-ejb3/howtoejb30mdb/doc/how-to-ejb30-mdb.html.

To implement an EJB 3.0 message-driven bean:

  1. Configure your message service provider.

    For more information, see:

  2. Create the message-driven bean class.

    You can create a plain old Java object (POJO) and define it as a message-driven bean with the @MessageDriven annotation.

  3. Configure message service provider information:

    You can define this information with the @ActivationConfigProperty annotation.

    For more information, see:

  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:

    For a JMS message-driven bean, implement the javax.jms.MessageListener interface to provide the onMessages method with 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 signature:

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

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

    For more information, see "Configuring a Lifecycle Callback Method for an EJB 3.0 MDB".

  8. Complete the configuration of your message-driven bean (see "Using EJB 3.0 MDB API").