Versions Compared

Key

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

This section describes how to configure WSO2 ESB to listen to a JMS queue.

 

The following sections walk you through the steps to configure the ESB to listen to a JMS queue, consume messages, and send the messages to a HTTP back­-end service.

Table of Contents
maxLevel4
minLevel4

Prerequisites

  • Configure WSO2 ESB with Apache ActiveMQ, and set up the JMS listener. For instructions, see Configure with ActiveMQ.
  • Start the ESB server.

Anchor
sample
sample

...

  • Create a proxy service with the following configuration. For information on how to create a proxy service, see Creating a Proxy Service.

    Code Block
    languagexml
    <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>
                   <send/>
               </outSequence>
           </target>
    </proxy>
    Tip
    titleProxy Service Configuration

    The OUT_ONLY property is set to true to indicate that message exchange is one-way.

    You can make the proxy service a JMS listener by setting the transport as jms. Once the JMS transport is enabled for a proxy service, the ESB starts listening on a JMS queue with the same name as the proxy service.

    If you take a look at the sample configuration above, the ESB 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 details, see below.

...

In addition to one-way invocations, an ESB 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 sending a request message to a JMS queue. The two-way HTTP call is illustrated in the diagram below:

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

Code Block
languagehtml/xml
<proxy xmlns="http://ws.apache.org/ns/synapse"
       name="Proxy1"
       transports="jms"
       startOnLoad="true"
       trace="disable">
   <description/>
   <target> 
      <inSequence>
         <send>
            <endpoint>
               <address uri="http://localhost:9000/services/SimpleStockQuoteService"/>
            </endpoint>
         </send>
      </inSequence>
      <outSequence>
         <send/>
      </outSequence>
   </target>
   <parameter name="transport.jms.ContentType">
      <rules>
         <jmsProperty>contentType</jmsProperty>
         <default>text/xml</default>
      </rules>
   </parameter>
</proxy>
Tip

In two-way JMS scenarios the OUT_ONLY property is not used.

Execute the following command from the <ESB_HOME>/samples/axis2Client directory.

Tip

See how the transport.jms.ReplyDestination element is specified.

Code Block
languagexml
ant stockquote -Dsymbol=WSO2 -Dtrpurl="jms:/JMStoHTTPStockQuoteProxy?transport.jms.ConnectionFactoryJNDIName=QueueConnectionFactory&java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory&java.naming.provider.url=tcp://localhost:61616&transport.jms.ContentTypeProperty=Content-Type&transport.jms.DestinationType=queue&transport.jms.ReplyDestination=ResponseQueue" 

You can view the responses from the back-end service in the ResponseQueue by accessing the ActiveMQ management console via http://0.0.0.0:8161/admin, and using admin as both the username and password.

Defining the content type of incoming JMS messages

By default, WSO2 ESB considers all messages consumed from a queue as a SOAP message. To accept messages consumed from a queue in a different format, define the transport.jms.ContentType parameter with the respective content type as a proxy service parameter.  
 
To define the content type of incoming JMS messages, you can modify the proxy service that you created above as follows:

Code Block
 <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>
               <send/>
           </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>

...