...
Follow the steps below to configure WSO2 ESB to listen to a JMS queue, consume messages, and send them to a HTTP back-end service. Anchor
Configure WSO2 ESB with Apache ActiveMQ and set up the JMS listener. For instructions, see Configure with ActiveMQ
.Start ActiveMQ by navigating to
<ACTIVEMQ_HOME/bin>
folder and executing./activemq console
(on Linux/OSX) oractivemq start
(on Windows).Start ESB by navigating to
<ESB_HOME/bin>
folder and executing./wso2server.sh
(on Linux/OSX) orwso2server.bat
(on Windows).Create a proxy service with the following configuration.To create a proxy service using ESB Tooling, see Working with Proxy Services via ESB Tooling.
Anchor sample sample 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 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 configuration above, ESB listens to a JMS queue namedJMStoHTTPStockQuoteProxy
. To make the proxy service listen to a different JMS queue, define thetransport.jms.Destination
parameter with the name of the destination queue.- To test this you will need an HTTP back-end service. Deploy the SimpleStockQuoteService and start the Axis2 server.
Place a message into the Apache ActiveMQ queue by executing the following command from
<ESB_HOME>/samples/axis2Client
folder.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"
...
Two-way HTTP Back-end Call
...
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:9765/services/t/superqa.com/Axis2Service"/> </endpoint> </send> </inSequence> <outSequence> <send/> </outSequence> </target> <parameter name="transport.jms.ContentType"> <rules> <jmsProperty>contentType</jmsProperty> <default>text/xml</default> </rules> </parameter> </proxy> |
Defining Content Type of Incoming JMS Messages
By default, WSO2 ESB considers all messages consumed from a queue as a SOAP message. 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. The sample code below
To demonstrate this, we have modified the above configuration as follows to connect to MyJMSQueue queue and read messages as POX messages.
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> |