Search This Blog

Saturday, July 6, 2013

JMS MapMessage support in WSO2 ESB 4.7.0

A JMS MapMessage is an object which is used to send a set of name value pairs over the jms transport. Now WSO2 ESB supports the jms mapmessage support in version 4.7.0. Let's go through a simple use case in which jms mapmessage can be used with esb.

First you have to configure ESB with a JMS broker. I have been using Apache ActiveMQ here. But you can use either IBM Websphere MQ, MSMQ or even WSO2 Mesage Broker.First get WSO2 ESB 4.7.0 and Apache ActiveMQ 5.8.0 (or lower version)

 Copy the following jars from AMQ_HOME/lib to ESB_HOME/repository/components/lib
  • activemq-broker-5.8.0.jar
  • activemq-client-5.8.0.jar
  • geronimo-j2ee-management_1.1_spec-1.0.1.jar
  • geronimo-jms_1.1_spec-1.1.1.jar
Enable the JMS Transport for ActiveMQ by uncommenting  the transportReceiver for activemq and transportSender for jms configurations found in the ESB_HOME/repository/conf/axis2/axis2.xml

Then you can start the ActiveMQ instance and then the ESB. So that your esb will be connected to ActiveMQ through JMS transport. Then only you can follow up with the mapmessage usage scenario

Now create a proxy service with the following configurations so that ESB will be creating a JMS endpoint and every request made to that proxy will be stored in a JMS queue. 

<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
       name="StockQuoteJMSProducerProxy"
       transports="http"
       statistics="disable"
       trace="disable"
       startOnLoad="true">
   <target>
      <inSequence>
         <property name="OUT_ONLY" value="true"/>
         <send>
            <endpoint>
               <address uri="jms:/SimpleStockQuoteService?transport.jms.ConnectionFactoryJNDIName=QueueConnectionFactory&amp;java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory&amp;java.naming.provider.url=tcp://localhost:61616"/>
            </endpoint>
         </send>
      </inSequence>
      <outSequence>
         <send/>
      </outSequence>
   </target>
   <publishWSDL uri="file:repository/samples/resources/proxy/sample_proxy_1.wsdl"/>
   <description/>
</proxy>


This proxy service can be used to implement a jms queue and if another proxy is created as a consumer then the message can be send to an actual SimpleStockQuote service endpoint and get a response. 

But here I am changing the SOAP message content to follows so that the content will be saved in a jms queue as a MapMessage. The content is

<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
<soapenv:Body>
<JMSMap xmlns="http://axis.apache.org/axis2/java/transports/jms/map-payload">
    <price>3.4566</price>
    <quantity>15000</quantity>
    <symbol>MSFT</symbol>
</JMSMap>
</soapenv:Body>
</soapenv:Envelope>


Now if you go to the queue named as StockQuoteJMSConsumerProxy you will see the message has been saved but as a MapMessage with name and value pairs.





No comments:

Post a Comment