Saturday, April 21, 2012

Axis2 JMS transport and ActiveMQ

In this post I will describe how to configure Axis2 JMS transport properly and test web services through JMS transport. For the simplicity I will use Apache ActiveMQ as the JMS server and will use ActiveMQ admin console as a JMS client to send and receive messages. In my future posts I will describe how to use ActiveMQ Maven plug-in with Axis2 and also how to test Axis2 JMS transports with few other implementations such as Apache QPID and WSO2 Message Broker.

First, If you don't have a ActiveMQ installation already, download the binary distribution from here and start the ActiveMQ server. If it's started properly make sure you can access to admin console through the following URL, we will use this admin console as a JMS client.
 http://0.0.0.0:8161/admin  
The next step is add requited dependencies and configure JMS transport in Axis2. Here I use Axis2 Simple HTTP server but same steps can be used with any other application server too.

(1) Add following dependencies to the "lib" directory of Axis2.

1.  axis2-transport-jms-1.x.x  (axis2-transport-jms-1.7.0-SNAPSHOT.jar or axis2-transport-jms-1.7.0 )
2.  axis2-transport-base-1.x.x (axis2-transport-base-1.7.0-SNAPSHOT.jar or axis2-transport-base- 1.7.0)  
3. geronimo-j2ee-management_1.1_spec-1.0.x  (geronimo-j2ee-management_1.1_spec-1.0.1.jar)
4. geronimo-jms_1.1_spec-1.1.x  (geronimo-jms_1.1_spec-1.1.1.jar)
5. activemq-core-5.1.x (activemq-core-5.1.0.jar)
6. coomons-io-2.1 (coomons-io-2.1.jar)

You can find above dependencies on Axis2 transport project here or you can find latest development snapshots from Apache build server here.

(2) Like in any other Axis2 transport your next task is to configure particular transport through the axis2.xml file by adding underline TransportListener  and  TransportSender. For the JMS transport you can add following settings.

 <transportReceiver name="jms" class="org.apache.axis2.transport.jms.JMSListener">  
   <parameter name="default" locked="false">             
     <parameter name="java.naming.factory.initial" locked="false">org.apache.activemq.jndi.ActiveMQInitialContextFactory</parameter>  
     <parameter name="java.naming.provider.url" locked="false">tcp://localhost:61616</parameter>      
     <parameter name="transport.jms.ConnectionFactoryJNDIName" locked="false">QueueConnectionFactory</parameter>  
   </parameter>  
 </transportReceiver>  

 <transportSender name="jms" class="org.apache.axis2.transport.jms.JMSSender">  
   <parameter name="default" locked="false">             
     <parameter name="java.naming.factory.initial" locked="false">org.apache.activemq.jndi.ActiveMQInitialContextFactory</parameter>  
     <parameter name="java.naming.provider.url" locked="false">tcp://localhost:61616</parameter>      
     <parameter name="transport.jms.ConnectionFactoryJNDIName" locked="false">QueueConnectionFactory</parameter>  
   </parameter>  
 </transportSender>  

Axis2 Transport user guide provide advanced configuration details such as separate configuration for JMS Queue and Topic etc.

(3) Start Axis2 server, If JMS transport is configured properly it is possible to see log message about JMS transport as follows.
 [INFO] JMS Sender started  
 [INFO] JMS ConnectionFactory : default initialized  
 [INFO] JMS Transport Sender initialized...  
 ..................  
 [INFO] JMS ConnectionFactory : default initialized  
 [INFO] JMS Transport Receiver/Listener initialized...  
 [INFO] Listening on port 8080  
 [INFO] JMS listener started  
 [INFO] Task manager for service : Version [re-]initialized  
 [INFO] Started to listen on destination : Version of type Queue for service Version  
 [INFO] Task manager for service : CalculatorService [re-]initialized  
 [INFO] Started to listen on destination : CalculatorService of type Queue for service CalculatorService  
 [INFO] Task manager for service : mtomService1Axis [re-]initialized  
 [INFO] Started to listen on destination : mtomService1Axis of type Queue for service mtomService1Axis  
 [INFO] [SimpleAxisServer] Started  
 [SimpleAxisServer] Started  

Now you have configured Axis2 JMS transport properly and it's possible to use any JMS client to invoke web services deployed on Axis2.  Let's try to invoke getVersion operation on Version web service through ActiveMQ admin console. Again in a browser go to the ActiveMQ admin console through the http://0.0.0.0:8161/admin URL, now  you have to select "Send" tab to reach the send wizard.  This wizard expect 3 basic inputs from you as input message, JMS destination ( in this case destination queue) and reply-to location. By looking at Axis2 server startup logs you can find hint about JMS destination bind to each web service, you can ensure availability of this JMS destination in ActiveMQ console too.
  [INFO] Started to listen on destination : Version of type Queue for service Version  

For our test scenario let's use following properties.
  •  Destination - Version
  •  Reply-To    - VersionResponse ( This destination is not available on ActiveMQ at this point, it will be created when the repose messages arrive to the JMS server)
  • In put message - Use following message
  •   - Add a random number
 <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:axis="http://axisversion.sample">  
   <soap:Header/>  
   <soap:Body>  
    <axis:getVersion/>  
   </soap:Body>  
 </soap:Envelope>  



Now you can see the response message by browsing "VersionResponse" Queue as follows.


1 comment:

Anonymous said...

nice idea.. thanks for sharing..