Skip to content

Consuming JMS Messages

This section describes how to configure WSO2 Micro Integrator to listen to a JMS Queue. First we need to configure JMS transport in micro integrator.

Configuring the JMS transport

To enable the JMS transport listener and sender, you need to configure JMS Transport respective to the message broker you are using.

Example 1: One-way messaging

In this example, the Micro Integrator listens to a JMS queue, consumes messages, and sends them to an HTTP back-end service.

Synapse configuration

Given below is the synapse configuration of the proxy service that mediates the above use case. Note that you need to update the JMS connection URL according to your broker as explained below.

<proxy xmlns="http://ws.apache.org/ns/synapse" name="JMStoHTTPStockQuoteProxy" transports="jms">
    <target>
        <inSequence>
            <property action="set" name="OUT_ONLY" value="true"/>
        </inSequence>
        <endpoint>
            <address uri="http://localhost:9000/services/SimpleStockQuoteService"/>
        </endpoint>
        <outSequence/>
    </target>
</proxy>

The Synapse artifacts used are explained below.

Artifact Type Description
Proxy Service A proxy service is used to receive messages and to define the message flow.
Endpoint Mediator To send a message to the HTTP backend, you should define the connection URL as the endpoint address.

Info

You can make the proxy service a JMS listener by setting its transport as jms. Once the JMS transport is enabled for a proxy service, the Micro Integrator listens on a JMS queue for the same name as the proxy service.
In the sample configuration above, the Micro Integrator listens to a JMS queue named JMStoHTTPStockQuoteProxy. To make the proxy service listen to a different JMS queue, define the transport.jms.Destination parameter with the name of the destination queue. For more information, you can refer details of the JMS transport parameters used in micro integrator.

Example 2: Two-way HTTP back-end call

In addition to one-way invocations, the proxy service can listen to the queue, pick up a message and do a two-way HTTP call as well. It allows the response to be delivered to a queue specified by the client. This is done by specifying a ReplyDestination element when placing a request message to a JMS queue.

Synapse configuration

We can have a proxy service similar to the following to simulate a two-way invocation:

<proxy xmlns="http://ws.apache.org/ns/synapse"
           name="JMStoHTTPStockQuoteProxy1"
           transports="jms"
           startOnLoad="true"
           trace="disable">
       <description/>
       <target> 
          <inSequence>
             <send>
                <endpoint>
                   <address uri="http://localhost:9000/services/SimpleStockQuoteService"/>
                </endpoint>
             </send>
          </inSequence>
          <outSequence/>
       </target>
       <parameter name="transport.jms.ContentType">
          <rules>
             <jmsProperty>contentType</jmsProperty>
             <default>text/xml</default>
          </rules>
       </parameter>
</proxy>
The Synapse artifacts used are explained below.

Artifact Type Description
Proxy Service A proxy service is used to receive messages and to define the message flow.
Send Mediator To send a message to the HTTP backend, you should define the connection URL as the endpoint address.

Info

You can make the proxy service a JMS listener by setting its transport as jms. Once the JMS transport is enabled for a proxy service, the Micro Integrator listens on a JMS queue for the same name as the proxy service.
In the sample configuration above, the Micro Integrator listens to a JMS queue named JMStoHTTPStockQuoteProxy1. To make the proxy service listen to a different JMS queue, define the transport.jms.Destination parameter with the name of the destination queue. For more information, you can refer details of the JMS transport parameters used in micro integrator.

Example 3: Set content type of incoming JMS messages

By default, the Micro Integrator considers all messages consumed from a queue as SOAP messages. To consider messages consumed from a queue as a different format, define the transport.jms.ContentType parameter with the respective content type as a proxy service parameter.

Synapse configuration

<proxy xmlns="http://ws.apache.org/ns/synapse" name="JMStoHTTPStockQuoteProxy" transports="jms">
    <target>
        <inSequence>
            <property action="set" name="OUT_ONLY" value="true"/>
            <send>
                <endpoint>
                    <address uri="http://localhost:9000/services/SimpleStockQuoteService"/>
                </endpoint>
            </send>
        </inSequence>
        <outSequence/>
    </target>
    <parameter name="transport.jms.ContentType">
        <rules>
            <jmsProperty>contentType</jmsProperty>
            <default>application/xml</default>
        </rules>
    </parameter>
    <parameter name="transport.jms.Destination">MyJMSQueue</parameter>
</proxy>

The Synapse artifacts used are explained below.

Artifact Type Description
Proxy Service A proxy service is used to receive messages and to define the message flow.
Send Mediator To send a message to the HTTP backend, you should define the connection URL as the endpoint address.

Info

You can specify a different content type within the transport.jms.ContentType parameter. In the sample configuration above, the content type defined is application/xml.If you want the proxy service to listen to a queue where the queue name is different from the proxy service name, you can specify the queue name using transport.jms.Destination parameter. In the sample configuration above, the Micro Integrator listens to a JMS queue named MyJMSQueue.For more information, you can refer details of the JMS transport parameters used in micro integrator.

Top