Apache Geronimo is bundled with an open source messaging provider called Active MQ. ActiveMQ supports JMS API and J2EE applications deployed in Geronimo can use the messaging capabilities of ActiveMQ by means of JMS. In the following article you will learn how to configure another third party messaging provider that supports JMS specification with Geronimo. The article includes two sample scenarios using OpenJMS, another open source messaging provider, and IBM WebSphere MQ as messaging provider.
Prerequisites for running this sample:
Websphere MQ 6.0
Integrating Third Party JMS Provider with Geronimo
Any third party JMS provider can be integrated with Geronimo by means of a JCA 1.5 resource adapter for JMS. The JMS RA wraps JMS API for creating connections to Queue's or Topic's and also provides Inbound Communication from a Queue or Topic.
The properties for the Resource Adapter are configured in the
ra.xml. These properties are:
Outbound properties - Used to create outbound queue and topic connections
- url - JNDI provider url (for example ldap://test/o=test,c=com, file: /C:/JNDI-Directory).
- icf - Initial Context Factory (for example com.sun.jndi.fscontext.RefFSContextFactory).
- name - Factory Name (for example gerQCF).
Inbound properties - Used to create inbound connections to MDB
- url - JNDI provider url.
- icf - Initial Context Factory.
- name - Factory Name.
- destination - Destination to pick messages form (for example queue name ivtQ).
Administered Objects - Used to define Queue and Topic Objects
- Physical Name - name of queue or topic created in JNDI of Geronimo
The geronimo-ra.xml contains Apache Geronimo specific properties for resource adapter. The following example shows an excerpt from the geronimo-ra.xml.
geronimo-ra.xml can be used to configure instances of resource adapters for different JMS providers. The example at the end of this article has two such configurations for OpenJMS and WebsphereMQ. The connection definition properties are changed for different JMS providers. The outbound communication of Resource Adapter uses these properties to get a connection factory and create connections to Queue or Topic.
Deploying JMS Resource Adapter
This section shows how to deploy a JMS Resource Adapter and configure a J2EE application to use OpenJMS and WebSphereMQ as JMS providers. RA can be deployed in the server scope and instances can be used within scope of application.
The following steps show how to deploy the JMS Resource Adapter and configure OpenJMS and WebSphereMQ providers for Geronimo.
OpenJMS starts RMI naming server on port 1019. This will conflict with the default RMI naming port in Geronimo. You will have to change the configuration for OpenJMS to use a different port and then start the OpenJMS server. Create QueueConnectionFactory and TopicConnectionFactory objects for OpenJMS. Define Queue's and Topics in
openjms.xml. The following example shows relevant sections of the configuration file.
Deploy a JMS Resource Adapter with server scope.
java -jar <geronimo_home>\bin\deployer.jar <sample_home>\externaljms-1.0.rar
Deploy an enterprise application that uses OpenJMS.
java -jar <geronimo_home>\bin\deployer.jar <sample_home>\externaljms.ear <sample_home>\geronimo-application-openjms.xml
The following example shows sections of Geronimo application plan for using OpenJMS. The properties for Outbound and Inbound communication are specified in the Message Bean and the Connector.
The properties configured in the geronimo-application.xml plan are:
- Resource Reference for ConnectionFactory.
- Resource Adapter Name.
- Activation Spec Configuration.
Resource Adapter Instance
- Connection properties.
- Administered Objects.
The following steps describe how you need to configure WebSphereMQ.
- Create a QueueManager ( GER_Q) in WMQ for Queues. A default local Queue is created called SYSTEM.DEFAULT.LOCAL.QUEUE
- Create and start a Listener than listens on port 1414
- Create and start a Server Connection Channel CHANNEL1.
- Create a QueueManager (GER_T) in WMQ for Topics and start it as broker from services.
- Create and start a Listener on port 1434 for this QueueManager.
- Create and start a Server Connection Channel CHANNEL1.
- Run MQSC command using the following file found in <MQ_Install_Dir>/java/bin/MQJMS_PSQ.mqsc ( runmqsc pubsub.qmgr < MQJMS_PSQ.mqsc )
- Create JNDI bindings for QueueConnectionFactory and TopicConnectionFactory using JMSAdmin tool.
- Set the JMSAdmin.config to use File Context JNDI and point to C:/JNDI-Directory
- Run the JMSAdmin tool and create the following bindings:
DEF QCF(gerQCF) HOST(localhost) PORT(1414) CHANNEL(CHANNEL1) QMGR(GER_Q) TRAN(client)
DEF Q(gerQ) QUEUE(SYSTEM.DEFAULT.LOCAL.QUEUE)
DEF TCF(gerTCF) HOST(localhost) PORT(1434) CHANNEL(CHANNEL1) QMGR(GER_T) TRAN(client)
DEF T(gerTopic) TOPIC(SampleTopic)
Test Outbound Communication
- Using the deployed WAR we can check outbound communication to queue or topic.
- Go to http://localhost:8080/jms
- Enter details and press Queue or Topic
- The message is sent to PhysicalName for Queue - queue1 in OpenJMS and SYSTEM.DEFAULT.LOCAL.QUEUE in WebSphereMQ.
- For Topic the message is sent to topic1 or SampleTopic.
- A sample subscriber can be started to check if the message is received. WMQ has a sample program called JMSPubSub.java which can be used to run a subscriber to SampleTopic or topic1. This can be found in <WebSphereMQ_home>/Tools/Java/jms/PubSub.java
Test Inbound Communication
- The deployed MDB acts as EndPoint to messages posted in a Queue.
- Post a test message in Queue in WebSphereMQ ( SYSTEM.DEFAULT.LOCAL.QUEUE) or queue1 in OpenJMS.
- The onMessage of MDB should be invoked and u should see a message in Console of Geronimo.
- The same can be extended to Topic by adding another ActivationSpec for Topics.
The RA for JMS does not support XA. This can be added to make WebsphereMQ or OpenJMS part of distributed transactions in Geronimo.
There is a sample GenericJMS RA with XA support available in Sun java.net. This RA can be deployed in Geronimo to get XA support for JMS Providers. Visit the following link for further details, http://genericjmsra.dev.java.net
Resource Adapter - RA
WebsphereMQ - WMQ
Message Driven Bean - MDB
externaljms.ear - EAR application and Source Code that contains WAR for Outbound and MDB for Inbound from RA
externaljms-1.0.rar - JMS Rresource adapter and Source Code.
geronimo-application-mq.xml - Geronimo plan for MQ.
geronimo-application-openjms.xml - Geronimo plan for OpenJMS.