Middleware
Application Server
First Created: 09-15-2006
Author: Sandeep Bangera

For the ActiveMQMessageDrivenEJBBeanIn the ejb-jar.xml deployment descriptor is declared as follows:
<message-driven>
<description>Message Driven Bean</description>
<display-name>ActiveMQMessageDrivenEJB</display-name>
<ejb-name>ActiveMQMessageDrivenEJB</ejb-name>
<ejb-class>com.oracle.howto.activemq.ActiveMQMessageDrivenEJBBean</ejb-class>
<messaging-type>javax.jms.MessageListener</messaging-type>
<transaction-type>Container</transaction-type>
<activation-config>
<activation-config-property>
<activation-config-property-name>destination</activation-config-property-name>
<activation-config-property-value> queue.inbound</activation-config-property-value>
</activation-config-property>
<activation-config-property>
<activation-config-property-name>destinationType</activation-config-property-name>
<activation-config-property-value>javax.jms.Queue</activation-config-property-value>
</activation-config-property>
<activation-config-property>
<activation-config-property-name>acknowledgeMode</activation-config-property-name>
<activation-config-property-value>Auto-acknowledge</activation-config-property-value>
</activation-config-property>
<activation-config-property>
<activation-config-property-name>messageSelector</activation-config-property-name>
<activation-config-property-value/>
</activation-config-property>
</activation-config>
</message-driven>
The activation-config-property is used to link MDB to JCA. The destination property value is only ActiveMQ specific and is the physical name of the queue on which the MDB listens to.
The two activation configuration defined above link to the following elements in ra.xml
<inbound-resourceadapter>
<messageadapter>
<messagelistener>
<messagelistener-type>javax.jms.MessageListener</messagelistener-type>
<activationspec>
<activationspec-class>org.apache.activemq.ra.ActiveMQActivationSpec</activationspec-class>
<required-config-property>
<config-property-name>destination</config-property-name>
</required-config-property>
<required-config-property>
<config-property-name>destinationType</config-property-name>
</required-config-property>
</activationspec>
</messagelistener>
</messageadapter>
</inbound-resourceadapter>
Update orion-ejb-jar.xml with the actual dest location JNDI info. This connects the inbound JMS Destination to the MDB
<message-driven-deployment name="ActiveMQMessageDrivenEJB" resource-adapter="activemq-rar"
connection-factory-location="activeMQ/QueueConnectionFactory" destination-location="activeMQJMS/MyQ">
</message-driven-deployment>
Update the transaction info for onMessage to be required in ejb.-jar.xml
<container-transaction>
<method>
<ejb-name>ActiveMQMessageDrivenEJB</ejb-name>
<method-name>onMessage</method-name>
<method-params>
<method-param>javax.jms.Message</method-param>
</method-params>
</method>
<trans-attribute>Required</trans-attribute>
</container-transaction>
<resource-ref>
<res-ref-name>jms/QCF</res-ref-name>
<res-type>javax.jms.QueueConnectionFactory</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Unshareable</res-sharing-scope>
</resource-ref>
<resource-env-ref>
<resource-env-ref-name>jms/QUEUE</resource-env-ref-name>
<resource-env-ref-type>javax.jms.Queue</resource-env-ref-type>
</resource-env-ref>
The jms/QCF is the JNDI name the ActiveMQEJBBean will use to lookup a javax.jms.QueueConnectionFactory. We will configure it to point to an ActiveMQ QueueConnectionFactory.
<session-deployment name="ActiveMQEJB">
<resource-ref-mapping name="jms/QCF" location="activeMQ/QueueConnectionFactory" />
<resource-env-ref-mapping name="jms/QUEUE" location="activeMQJMS/MyQ" />
</session-deployment>
The following snippet links the Outbound queue . The following snippet is in oc4j-connectors.xml
<connector name="activemq-rar" path="activemq-ra.rar" >
<adminobject-config location="activeMQJMS/MyQ">
<adminobject-class>org.apache.activemq.command.ActiveMQQueue</adminobject-class>
<config-property name="PhysicalName" value="queue.outbound"/>
</adminobject-config>
<adminobject-config location="activeMQJMS/MyT">
<adminobject-class>org.apache.activemq.command.ActiveMQTopic</adminobject-class>
<config-property name="PhysicalName" value="topic.outbound"/>
</adminobject-config>
</connector>
The connection factory is linked in oc4j-ra.xml
<connector-factory location="activeMQ/QueueConnectionFactory" connector-name="activemq-rar">
<connection-pooling use="none">
</connection-pooling>
<security-config use="none">
</security-config>
<connectionfactory-interface>javax.jms.QueueConnectionFactory</connectionfactory-interface>
</connector-factory>
The following instructions are for running this demonstration on a standalone instance of Oracle Containers for J2EE 10g (10.1.3).
Note that the oc4j command expects the JAVA_HOME environment variable to point to a full JDK installation.
Note that the activemq command expects the JAVA_HOME environment variable to point to a full JDK installation.
You need to install ActiveMQ 4by downloading the binaries from here.
Open a new console window. set the env variables ORACLE_HOME, ACTIVEMQ_HOME, JAVA_HOME as explained here. To run the application, type the following command from the %HOWTO_HOME% directory:
You should now have the newly created active-mq.ear in your %HOWTO_HOME%/lib directory.
This command would attempt to deploy the application if the build is successful. It will first test whether OC4J is running. After deploying it will also run the test .The test will execute the JMS client which will post a message to the ActiveMQ inbound queue on which the MDB is listening via the ActiveMQ Resource Adapter
You should see this message on the console where you typed ant.
" Sent message: Hello world to ActiveMQ inbound queue!"
Return to the console where you started OC4J and you will see output generated by the MDB and Stateless E JB.
"Inside MDB, received from inbound queue: Hello world to ActiveMQ inbound queue!
Message Received from MDB inside Session Bean: Hello world to ActiveMQ inbound queue!
Sending Message from Stateless EJB to ActiveMQ outbound queue: Hello world to ActiveMQ inbound queue!"
To verify if the message posted by Stateless EJB to the ActiveMQ outbound queue "queue.outbound" was correctly received by ActiveMQ we will use jconsole ( JMX Browser available by default with JDK15.



Note that you can also deploy the application separately . Ensure the %ORACLE_HOME% environment variable is defined, and from the %HOWTO_HOME% directory, type the command: