This section describes how to configure WSO2 ESB to listen to a JMS Queuequeue.
Diagram 1 : Simple JMS to HTTP proxy service
The following example code shows the configuration of WSO2 The following sections walk you through the steps to configure the ESB to listen to a JMS queue, consume messages, and send them the messages to a HTTP backback-end service. Anchor
Table of Contents maxLevel 4 minLevel 4
Prerequisites
- Configure WSO2 ESB with Apache ActiveMQ, and set up the JMS listener. For instructions, see Configure with ActiveMQ.
- Start the ESB server.
Anchor | ||||
---|---|---|---|---|
|
Create a proxy service with the following configuration. For information on how to create a proxy service, see Creating a Proxy Service.
Code Block language
...
xml
...
<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 title Proxy Service Configuration The
OUT_ONLY
property is set totrue
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 thetransport.jms.Destination
parameter with the name of the destination queue. For details, see below.
Testing the sample
To test this sample, you need an HTTP back-end service, refer to Starting Sample Back-End Services and to configure JMS Listener for Apache ActiveMQ, refer to Setting up the JMS Listener.
To place a message into JMS queue, execute following command from . Let's use the SimpleStockQuoteService
as the back-end service and test the sample.
- Follow the steps below to build and deploy the
SimpleStockQuoteService
:- Open a command prompt (or a shell in Linux) and go to the
<ESB_HOME>/samples/axis2Server/src/SimpleStockQuoteService
directory. Run
ant
.
- Open a command prompt (or a shell in Linux) and go to the
Follow the steps below to start the Axis2 server:
- Open a command prompt (or a shell in Linux) and go to the
<ESB_HOME>/samples/axis2Server
directory. - Execute one of the following commands
- On Windows:
axis2server.bat
- On Linux/Solaris:
./axis2server.sh
- On Windows:
- Open a command prompt (or a shell in Linux) and go to the
Send a message to the ActiveMQ queue by executing the following command from the
<ESB_HOME>/samples/axis2Client
...
directory.
...
Code Block language xml ant stockquote -Dmode=placeorder -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"
Analyzing the output
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, ESB will start listening on a JMS queue with the same name as the proxy service. In the sample code above, 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 queuewill see the following response on the Axis2 Server console:
Code Block | ||
---|---|---|
| ||
Fri Dec 16 10:21:11 GST 2016 samples.services.SimpleStockQuoteService :: Accepted order #1 for : 7424 stocks of IBM at $ 156.74347214873563 |
By analyzing the output you can understand that the ESB has read the message from the ActiveMQ queue and sent it to the back-end service.
Two-way HTTP
...
back-end
...
call
In addition to one-way invocations, WSO2 an ESB proxy service can listen to the queue, pick up a message and do a two-way HTTP call as well. This is done when the client specifies a replyDestination element when placing a request message to a JMS queue. It allows the response to be delivered to the replyDestination a queue specified by the client. The scenario is depicted 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.:
Code Block | ||
---|---|---|
| ||
<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:97659000/services/t/superqa.com/Axis2ServiceSimpleStockQuoteService"/> </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 Execute the following command from the
|
...
You can view the responses from the back-end service in the |
Defining the content type of incoming JMS messages
By default, WSO2 ESB considers all messages consumed from a queue as a SOAP message. To consider accept messages consumed from a queue as in a different format, define the transport.jms.ContentType
parameter with the respective content type as a proxy service parameter. The sample code below
To demonstrate this, we have modified the sample code 1 as follows to connect to MyJMSQueue queue and read messages as POX messages.
...
language | html/xml |
---|---|
title | Sample Code 2 |
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> |
Anchor | ||||
---|---|---|---|---|
|
Tip | ||
---|---|---|
| ||
You can specify a different content type within the 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 the |