Oracle® Containers for J2EE Enterprise JavaBeans Developer's Guide 10g (10.1.3.1.0) Part Number B28221-02 |
|
|
View PDF |
EJB 3.0 greatly simplifies the development of enterprise beans, removing many complex development tasks. For example:
The bean class can be a 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/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:
Configure your message service provider.
For more information, see the following:
Create the message-driven bean class.
You can create a POJO and define it as a message-driven bean with the @MessageDriven
annotation.
Configure message service provider information as follows:
You can define this information with the @ActivationConfigProperty
annotation.
For more information, see the following:
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 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).
Optionally, implement the javax.ejb.TimedObject
interface.
Implement the ejbTimeout
method with the following signature:
public void ejbTimeout(javax.ejb.Timer timer)
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".
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").
Complete the configuration of your message-driven bean (see "Using an EJB 3.0 Message-Driven Bean").