Saturday, April 23, 2016

In and Out of JMS queue using WSO2 ESB

In this example we'll take a look at inserting a message to a JMS queue via a proxy service in WSO2 ESB, and how to pull it from the queue using an Inbound Endpoint


Part 1: Get Message From Queue

For the first part we will be using Sample 901 which ships with ESB 4.9.0.

Install ActiveMQ and follow steps in the following sample 901:
https://docs.wso2.com/display/ESB490/Sample+901%3A+Inbound+Endpoint+JMS+Protocol+Sample


For the first part you need to start the ESB with Sample configuration 901.
in <ESB_HOME>/bin
wso2esb-samples.bat -sn 901 for Windows

./wso2esb-samples.sh -sn 901 in Linux


Deploy SimpleStockQuoteService:

Run ant from <ESB_HOME>/samples/axis2Server/src/SimpleStockQuoteService


Then start the Axis2 Server at <ESB_HOME>/samples/axis2Server and send a message to the queue as shown in the sample.


Output - you will see a stock quote for IBM generated  in the Axis2 Server console.


Part 2: Put message to queue using proxy service

Create a pass through proxy and modify the source configuration with the following:

<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
       name="StockQuoteProxyToJMSQueue"
       transports="http"
       statistics="disable"
       trace="disable"
       startOnLoad="true">
   <target>
      <inSequence>
         <property name="OUT_ONLY" value="true"/>
         <property name="FORCE_SC_ACCEPTED" value="true" scope="axis2"/>
         <send>
            <endpoint>
               <address uri="jms:/ordersQueue?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"/>
            </endpoint>
         </send>
      </inSequence>
   </target>
   <description/>
</proxy>


The above is a pretty simple configuration that will forward the message sent to the proxy to the JMS queue.

You can get the WSDL file for the proxy service and invoke the proxy via SoapUI with the same payload shown in Sample 901. The end-to-end scenario will be when you send a message to the proxy the proxy will forward it to the JMS queue, and the inbound endpoint will pick it from the queue and send it to the SimpleStockQuoteService

--

No comments:

Post a Comment