This documentation is for WSO2 ESB version 4.5.1. View documentation for the latest release.

Sample 250: Introduction to Switching Transports

Objective: Introduction to switching transports (JMS to HTTP/S) with Proxy Services.

Prerequisites
  • Start the Axis2 server and deploy the SimpleStockQuoteService.
  • Download, install and start a JMS server, and configure ESB to listen on JMS.
  • Start the Synapse configuration numbered 250: wso2esb-samples.sh -sn 250
<definitions xmlns="http://ws.apache.org/ns/synapse">
    <proxy name="StockQuoteProxy" transports="jms">
        <target>
            <inSequence>
                <property action="set" name="OUT_ONLY" value="true"/>
            </inSequence>
            <endpoint>
                <address uri="http://localhost:9000/services/SimpleStockQuoteService"/>
            </endpoint>
            <outSequence>
                <send/>
            </outSequence>
        </target>
        <publishWSDL uri="file:repository/samples/resources/proxy/sample_proxy_1.wsdl"/>
        <parameter name="transport.jms.ContentType">
            <rules>
                <jmsProperty>contentType</jmsProperty>
                <default>application/xml</default>
            </rules>
        </parameter>
    </proxy>
</definitions>

For this example we use ActiveMQ as the JMS provider. Once ActiveMQ is installed and started you should get a message as follows:

INFO BrokerService - ActiveMQ JMS Message Broker (localhost) started

You will now need to configure the Axis2 instance used by ESB (not the sample Axis2 server) to enable JMS support using the above provider. Refer to the Axis2 documentation on setting up JMS for more details (http://ws.apache.org/axis2/1_1/jms-transport.html). You will also need to copy the ActiveMQ client JAR files activemq-core-5.2.0.jar and geronimo-j2ee-management_1.0_spec-1.0.jar into the repository/components/lib directory to allow ESB to connect to the JMS provider.

For a default ActiveMQ version 4.0 installation, you may uncomment the Axis2 transport listener configuration found at repository/conf/axis2.xml as

<transportReceiver name="jms"> ...

You need to enable the JMS transport sender for the ESB to be able to send messages over the JMS transport. To enable the JMS transport sender, uncomment the Axis2 transport sender configuration found at repository/conf/axis2.xml as

<transportSender name="jms" />

Once you start the Synapse configuration and request for the WSDL of the proxy service (http://localhost:8280/services/StockQuoteProxy?wsdl) you will notice that its exposed only on the JMS transport. This is because the configuration specified this requirement in the Proxy Service definition.

Now lets send a stock quote request on JMS, using the dumb stock quote client as follows:

ant jmsclient -Djms_type=pox -Djms_dest=dynamicQueues/StockQuoteProxy -Djms_payload=MSFT

On the ESB debug log, you will notice that the JMS listener received the request message as:

[JMSWorker-1] DEBUG ProxyServiceMessageReceiver -Proxy Service StockQuoteProxy received a new message...

Now if you examine the console running the sample Axis2 server, you will see a message indicating that the server has accepted an order as follows:

Accepted order for : 16517 stocks of MSFT at $ 169.14622538721846

In this sample, client sends the request message to the proxy service exposed in JMS in Synsape. ESB forwards this message to the HTTP EPR of the simple stock quote service hosted on the sample Axis2 server, and returns the reply back to the client through a JMS temporary queue.

Note

It is possible to instruct a JMS Proxy Service to listen to an already existing destination without creating a new one. To do this, use the property elements on the proxy service definition to specify the destination and connection factory etc.

<property name="transport.jms.Destination" value="dynamicTopics/something.TestTopic"/>