Programming EJB 3.0 Compliant MDBs

You must use the @javax.ejb.MessageDriven annotation to declare the EJB type as message-driven. You can specify the following optional attributes:

messageListenerInterface—Specifies the message listener interface, if you haven't explicitly implemented it or if the bean implements additional interfaces.

Note:

The bean class must implement, directly or indirectly, the message listener interface required by the messaging type that it supports or the methods of the message listener interface. In the case of JMS, this is the javax.jms.MessageListener interface.

activationConfig—Specifies an array of activation configuration properties that configure the bean in its operational environment.

Activation configuration properties are name-value pairs that are passed to the MDB container when an MDB is deployed. The properties can be declared in either an ejb-jar.xml deployment descriptor or by using the @ActivationConfigProperty annotation on the MDB bean class. An example using the @ActivationConfigProperty annotation is shown in Example 7-1. An example using the ejb-jar.xml deployment descriptor is shown in Example 7-2.

Because activation configuration properties can be set in an ejb.jar deployment descriptor or by using activationConfigProperty annotation properties, conflicts may result if the same name is used in both places. Conflicts may also result from using same-named properties from pre-3.0 versions of EJB or from proprietary WebLogic Server EJB annotations. Such conflicts are resolved following the following priority order, in sequence from high to low is

Properties set in the weblogic-ejb-jar.xml deployment descriptor

Proprietary WebLogic Server 10.0 (and later) annotations

activation-config-property properties set in the ejb-jar.xml deployment descriptor

activationConfigProperty annotation properties

For example, if the same property exists in the weblogic-ejb-jar.xml descriptor and the ejb-jar.xml descriptor, the one in weblogic-ejb-jar.xml has the higher priority and overrides the one in ejb-jar.xml value. Or, if the same property is set in both an ejb-jar.xml descriptor element and in an activationConfigProperty annotation, the descriptor element takes precedence and the annotation is ignored.

For more information about activation configuration properties, see "javax.ejb.ActivationConfigProperty" in Programming WebLogic Enterprise JavaBeans, Version 3.0 for Oracle WebLogic Server. Also see Table 11-1, which summarizes the activation configuration properties supported by WebLogic Server.

MDB Sample Using Annotations

Example 7-3 shows a WebLogic MDB that uses a subscription to a WebLogic JMS queue (from WebLogic Server 10.3.4 or later), transactionally processes the messages, and forwards the messages to a target destination.

The MDB connects using JMS connection factory MyCF to receive from queue MyQueue. It forwards the messages to MyTargetDest using a connection generated from connection factory MyTargetCF.