Configuring a Session Bean to send messages to ActiveMQIn the attached example application, the three MDBs use the
The BeanIn the ejb-jar.xml deployment descriptor, the ejb-jar.xml – session bean declaration <session> ... <ejb-name>SenderEJB</ejb-name> ... <ejb-class>com.panacya.platform.service.bus.sender.SenderBean</ejb-class> ... <resource-ref> <res-ref-name>jms/MyQueueConnectionFactory</res-ref-name> <res-type>javax.jms.QueueConnectionFactory</res-type> ... </resource-ref> <message-destination-ref> <message-destination-ref-name>jms/LogQueue</message-destination-ref-name> <message-destination-type>javax.jms.Queue</message-destination-type> ... <message-destination-link>LoggingQueue</message-destination-link> </message-destination-ref> </session> The The ejb-jar.xml – assembly descriptor section <assembly-descriptor> ... <message-destination> <message-destination-name>LoggingQueue</message-destination-name> </message-destination> ... </assembly-descriptor> This is a standard EJB deployment descriptor, nothing special. The ConnectorThe ra.xml – The QueueConnectionFactory <outbound-resourceadapter> ... <connection-definition> ... <connectionfactory-interface>javax.jms.QueueConnectionFactory</connectionfactory-interface> <connectionfactory-impl-class>org.activemq.ra.ActiveMQConnectionFactory</connectionfactory-impl-class> <connection-interface>javax.jms.QueueConnection</connection-interface> ... </connection-definition> ... </outbound-resourceadapter> The ra.xml – The Queue <adminobject> <adminobject-interface>javax.jms.Queue</adminobject-interface> <adminobject-class>org.activemq.message.ActiveMQQueue</adminobject-class> <config-property> <config-property-name>PhysicalName</config-property-name> <config-property-type>java.lang.String</config-property-type> </config-property> </adminobject> The GlueIn JBoss, connecting the resources needed by the ejb-jar.xml file to resources provided by the ra.xml file involves two additional files:
panacya-jms-ds.xml – The JBoss Data Source FileThis first snippet configures the panacya-jms-ds.xml – The QueueConnectionFactory <tx-connection-factory> <jndi-name>activemq/QueueConnectionFactory</jndi-name> <xa-transaction/> <rar-name>activemq-ra-1.2-SNAPSHOT.rar</rar-name> <connection-definition>javax.jms.QueueConnectionFactory</connection-definition> <security-domain-and-application>JmsXARealm</security-domain-and-application> </tx-connection-factory> This second snippet configures the panacya-jms-ds.xml – The Queue <mbean code="org.jboss.resource.deployment.AdminObject" name="activemq.queue:name=outboundQueue"> <attribute name="JNDIName">activemq/queue/outbound</attribute> <depends optional-attribute-name="RARName">jboss.jca:service=RARDeployment,name='activemq-ra-1.2-SNAPSHOT.rar'</depends> <attribute name="Type">javax.jms.Queue</attribute> <attribute name="Properties"> PhysicalName=queue.outbound </attribute> </mbean> In the panacya-jms-ds.xml file section shown above, the value of the jboss.xml – The JBoss Deployment DescriptorThis first snippet links the jboss.xml – The QueueConnectionFactory for the SenderEJB <enterprise-beans> <session> <ejb-name>SenderEJB</ejb-name> <resource-ref> <res-ref-name>jms/MyQueueConnectionFactory</res-ref-name> <resource-name>queuefactoryref</resource-name> </resource-ref> </session> ... </enterprise-beans> This second snippet links the local jboss.xml – Linking queuefactoryref to the global JNDI namespace <resource-managers> <resource-manager> <res-name>queuefactoryref</res-name> <res-jndi-name>java:/activemq/QueueConnectionFactory</res-jndi-name> </resource-manager> ... </resource-managers> This third snippet links the jboss.xml – Linking LoggingQueue to the global JNDI namespace <assembly-descriptor> <message-destination> <message-destination-name>LoggingQueue</message-destination-name> <jndi-name>activemq/queue/outbound</jndi-name> </message-destination> </assembly-descriptor> The above example highlights the key configuration settings needed to enable EJBs deployed in JBoss to send JMS messages to an ActiveMQ destination. You can try the above example, plus a few more, by downloading the activemq-jboss-test.zip file which contains the complete sample project. |