Oracle® Containers for J2EE Enterprise JavaBeans Developer's Guide 10g Release 3 (10.1.3) B14428-02 |
|
![]() Previous |
![]() Next |
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 |
For more information, see:
EJB 3.0 greatly simplifies the development of EJBs, removing many complex development tasks. For example:
The bean class can be a plain old Java object (POJO); it does not need to implement javax.ejb.MessageDrivenBean
.
Annotations are used for many features, including the message destination and topic (or queue) factory
You can use injection to acquire a MessageDrivenEntityContext
.
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:
Configure your message service provider.
For more information, see:
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.
Configure message service provider information:
You can define this information with the @ActivationConfigProperty
annotation.
For more information, see:
Add a data member for the MessageDrivenContext
.
You can use resource injection to easily initialize this data member without getter and setter methods.
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).
Optionally, implement the javax.ejb.TimedObject
interface.
Implement the ejbTimeout
method with signature:
public void ejbTimeout(javax.ejb.Timer timer)
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".
Complete the configuration of your message-driven bean (see "Using EJB 3.0 MDB API").