Sunday, February 17, 2013

How to send http messages to jms endpoint using WSO2 ESB

WSO2 ESB can route incomming messages to various endpoint type. This blog shows how to configure esb http proxy service to send incomming messages to jms queue.

Download WSO2 ESB and  ActiveMQ.  ActiveMQ is used as the jms broker.

Uncomment following configuration from axis2.xml to enable jms transport in WSO2 ESB. axis2.xml can be found in $WSO2_ESB_HOME/repository/axis2.aml or repository/axis2/axis2.xml

Copy below jars

activemq-core-5.7.0.jar
geronimo-j2ee-management_1.1_spec-1.0.1.jar
geronimo-jms_1.1_spec-1.1.1.jar

to $WSO2_ESB_HOME/repository/components/lib. Those jar file can be found from $ActiveMQ_HOME/lib directory

<transportReceiver name="jms" class="org.apache.axis2.transport.jms.JMSListener">  
     <parameter name="myTopicConnectionFactory" 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">TopicConnectionFactory</parameter>  
           <parameter name="transport.jms.ConnectionFactoryType" locked="false">topic</parameter>  
     </parameter>  
     <parameter name="myQueueConnectionFactory" 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 name="transport.jms.ConnectionFactoryType" locked="false">queue</parameter>  
     </parameter>  
     <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 name="transport.jms.ConnectionFactoryType" locked="false">queue</parameter>  
     </parameter>  
   </transportReceiver>  

 <transportSender name="jms" class="org.apache.axis2.transport.jms.JMSSender"/>

Start jms broker(./activemq console) and create  a queue named TestQueue(go to http://0.0.0.0:8161/admin/).

Then Start WSO2 ESB Server(./wso2server.sh) and create a proxy service and a endpoint from bellow configuration

<proxy name="proxyWithJmsEndpoint" transports="https http" startOnLoad="true" trace="disable">  
     <target endpoint="jmsEndpoint">  
       <inSequence>  
         <property name="OUT_ONLY" value="true"/>  
         <property name="FORCE_SC_ACCEPTED" value="true" scope="axis2"/>  
       </inSequence>  
       <outSequence>  
         <drop/>  
       </outSequence>  
     </target>  
   </proxy>  


<endpoint name="jmsEndpoint">  
     <address uri="jms:/TestQueue?transport.jms.ConnectionFactoryJNDIName=QueueConnectionFactory&amp;java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory&amp;java.naming.provider.url=tcp://127.0.0.1:61616&amp;transport.jms.DestinationType=queue" format="pox"/>  
   </endpoint>  

In endpoint, uri format is pox. so it remove the soap envelop and send actual payload. It is useful for REST Services. If you want to send SOAP messages to queue remove format.

Now We have finished the configuration. Since this is a one-way message, the property “OUT_ONLY” is set to true and “FORCE_SC_ACCEPTED” property is defined to send a 202 response to the client who invokes this proxy.

 once you send a SOAP messages via http transport to above proxy service, It will send the messages to TestQueue. 



3 comments:

  1. Normally when an error occurs in processing (MessageProcessor) JMS queue and goes to faultSequence and is not removed from the queue. My doubt is in some fault codes that I need to remove the message from the JMS queue even being a FAULT. Could you help me.

    ReplyDelete
  2. Hi Nuwan, Ive stumbled over, and am going to attempt a ressurection of this blog in the context of some WSO2 PoC work Im doing at the moment.

    Im stuck with a problem that I feel should be fixed in a second using the solution you describe above - Im posting fully formed soap over JMS to a proxy service which in turn is attempting a verbatim relay of the contents to a webservice endpoint. The problem is I can see the payload being wrapped by the elements below by some native feature of WSO2.
    Ive tried setting the endpoint format to "pox", ive tried setting the endpoint format through the designer UI to "leave as-is" (which I believe eliminates the format attribute entirely). No luck, I always see my content wrapped by the tag below.

    This is what the format attribute is designed for right, I dont feel as though I should need to start xslt in order to clean up these tags??






    ReplyDelete