Skip Headers

Oracle® Containers for J2EE Enterprise JavaBeans Developer's Guide 10g Release 3 (10.1.3) B14428-01 |
| Home | Solution Area | Contents | Index

Previous | Next |

# Configuring an EJB 3.0 MDB to Use a J2CA Message Service Provider

You can configure an EJB 3.0 MDB to use a J2CA message service provider using annotations (see "Using Annotations").

For more information, see "J2EE Connector Architecture (J2CA) Adapter Message Provider".

## Using Annotations

You associate an EJB 3.0 MDB with a J2CA message service provider using the `@MessageDriven` annotation `activationConfig` attribute and `@MessageDrivenDeployment` annotation `resourceAdapter` attribute. You must use `@MessageDrivenDeployment` annotation to specify the resource adapter that your message-driven bean uses.

Example 10-3 shows how to configure a message-driven bean to use the Oracle JMS resource adapter named "OracleASjms". It assumes that connection factory `OracleASjms/MyQCF` is defined in `oc4j-ra.xml` file and destination name `OracleASjms/MyQueue` is defined in `oc4j-connectors.xml` file. For more information on configuring a J2CA message service provider, see "Configuring a Message Service Provider Using J2CA".

Example 10-2 @MessageDriven and @MessageDrivenDeployment Annotation for a J2CA Message Service Provider

    import javax.ejb.ActivationConfigProperty;
    import javax.ejb.MessageDriven;
    import javax.jms.Message;
    import javax.jms.MessageListener;

    // Oracle deployment annotation for MDB
    import oracle.j2ee.ejb.MessageDrivenDeployment;

    @MessageDriven(
        activationConfig = {
            @ActivationConfigProperty(
                propertyName="ConnectionFactoryJndiName", propertyValue="OracleASjms/MyQCF"),
            @ActivationConfigProperty(
                propertyName="DestinationName", propertyValue="OracleASjms/MyQueue"),
            @ActivationConfigProperty(
                propertyName="DestinationType", propertyValue="javax.jms.Queue"),
            @ActivationConfigProperty(
                propertyName="messageSelector", propertyValue="RECIPIENT = 'simple_jca_test'")
        })

    // associate MDB with the resource adapter
    @MessageDrivenDeployment(resourceAdapter = "OracleASjms")

    public class JCAQueueMDB implements MessageListener
    {
        public void onMessage(Message msg)
        {
            ...
        }
    }

The `@MessageDriven` annotation `activationConfig` attribute contains a list of `@ActivationConfigProperty` annotations whose `propertyName` and `propertyValue` attributes you use to specify activation configuration properties. Table 10-2 lists the mandatory and commonly used activation configuration properties you must set.

Table 10-3 Mandatory @ActivationConfigProperty Attributes

Property Name | Value
--- | ---
`connectionFactoryJndiName` | The JNDI name of the message service provider connection factory. You define this name when you configure your message service provider.
`destinationName` | The JNDI name of the message service provider destination name. You define this name when you configure your message service provider
`destinationType` | Specify the fully qualified class name of the destination type for your message service provider. For a JMS MDB, either `javax.jms.Queue` or `javax.jms.Topic`.
`messageSelector` | Specify the boolean expression of message properties that match the type of message your MDB should receive.

For a complete list of all activation configuration properties, download and unzip one of the `how-to-gjra-with-xxx.zip` files from `http://www.oracle.com/technology/tech/java/oc4j/1013/how_to/index.html`, where `xxx` is the name of the relevant resource provider. The `orion-ejb-jar.xml` demo file contains comments describing all activation configuration properties. For more information, see "JMS Resource Adapter" in the Oracle Containers for J2EE Services Guide.

You may also set the optional attributes that Table A-4 lists.

The actual names you use depend on your message service provider installation. For more information, see "J2CA Message Service Provider Connection Factory Names".

## Using Deployment XML

You can associate an EJB 3.0 MDB with a J2CA message service provider using the `orion-ejb-jar.xml` file by configuring the `message-driven-deployment` element with an `activation-config` element and setting the `message-driven-deployment` element `resource-adapter` attribute as you would for an EJB 2.1 MDB. Configuration in the `orion-ejb-jar.xml` file will overide annotations, if present.

For more information, see "Using Deployment XML".