Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

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

Prerequisites

...

Table of Contents
maxLevel3

Introduction

This sample demonstrates how the ESB receives a messages over the JMS transport and forwards it over a HTTP/S transport.. In this sample, the client sends a request message to the proxy service exposed in JMS. The 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.

Prerequisites

  • Configure WSO2 ESB's JMS transport with ActiveMQ and enable the JMS transport listener and sender. For information on how to configure with ActiveMQ, and how to enable the JMS transport listener and sender, see Configure with ActiveMQ.

    Note
    titleNote

    If you are using ActiveMQ version 5.8.0 or above, you need to copy the hawtbuf-1.2.jar file from the <ActiveMQ>/lib directory to the <ESB_HOME>/repository/components/lib directory.

  • For a list of prerequisites, see Prerequisites to Start the ESB Samples.

Building the sample

The XML configuration for this sample is as follows:

Code Block
languagehtml/xml
linenumberstrue
<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:

Code Block
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 must also copy activemq-core-5.7.0.jar, geronimo-j2ee-management_1.1_spec-1.0.1.jar, and geronimo-jms_1.1_spec-1.1.1.jar from <ActiveMQ_HOME>/lib to This configuration file  synapse_sample_250.xml is available in the <ESB_HOME>/repository/components/lib to allow the 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/axis2.xml as

Code Block
<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/axis2.xml as

Code Block
<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:

...

samples directory.

To build the sample

  1. Start the ESB with the sample 250 configuration. For instructions on starting a sample ESB configuration, see Starting the ESB with a sample configuration.

    The operation log keeps running until the server starts, which usually takes several seconds. Wait until the server has fully booted up and displays a message similar to "WSO2 Carbon started in n seconds."

  2. Start the Axis2 server.

  3. Deploy the back-end service SimpleStockQuoteService. For instructions on deploying sample back-end services, see Deploying sample back-end services.

    Now you have a running ESB instance and a back-end service deployed. In the next section, we will send a message to the back-end service through the ESB using a sample client.

Executing the sample

To execute the sample JMS client

  • Run the following command from the <ESB_HOME>/samples/axis2Client directory:

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

...

Analyzing the output

When you run the client and analyze the ESB debug log, you will notice that the see the following entry, which shows that the JMS listener received the request message as::

When you run the client, it sends a plain XML formatted place order request to a JMS queue named StockQuoteProxy. The ESB polls on this queue for any incoming messages and picks up the request. If you run the ESB in the DEBUG mode, you will see the following entry on the console.

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

Now if you examine Then, the ESB mediated the request and forwards it to the sample Axis2 server over HTTP. If you analyze the console running the sample Axis2 server, you will see a the following message indicating that the server has accepted an order as follows:

Code Block
Accepted order for : 16517 stocks of MSFT at $ 169.14622538721846

...

Info
titleNote

It is possible to instruct a JMS Proxy Service 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.

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

...