Sample 264: Request-Response Invocations with the JMS Transport

<definitions xmlns="http://ws.apache.org/ns/synapse"> <proxy name="StockQuoteProxy" transports="http"> <target> <endpoint> <address uri="jms:/SimpleStockQuoteService?transport.jms.ConnectionFactoryJNDIName=QueueConnectionFactory&java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory&java.naming.provider.url=tcp://localhost:61616&transport.jms.DestinationType=queue"/> </endpoint> <inSequence> <property action="set" name="transport.jms.ContentTypeProperty" value="Content-Type" scope="axis2"/> </inSequence> <outSequence> <property action="remove" name="TRANSPORT_HEADERS" scope="axis2"/> <send/> </outSequence> </target> <publishWSDL uri="file:repository/conf/sample/resources/proxy/sample_proxy_1.wsdl"/> </proxy> </definitions>

Objective

In sample 251 we saw how to perform transport switching between HTTP and JMS using a one-way invocation. Here we will do HTTP to JMS switching with a two-way, request-response invocation.

Pre-requisites

  • Setup and start a JMS broker (Apache ActiveMQ can be used as the JMS broker for this scenario. Refer JMS setup guide for information on how to run ActiveMQ.)
  • Enable the JMS transport receiver of the sample Axis2 server (Refer JMS setup guide for details)
  • Deploy the SimpleStockQuoteService in the sample Axis2 server and start Axis2 (Since the JMS receiver is enabled, Axis2 will start polling on a JMS queue)
  • Start Synapse using the configuration numbered 264 (repository/conf/sample/synapse_sample_264.xml)
    Unix/Linux: sh synapse.sh -sample 264
    Windows: synapse.bat -sample 264

Executing the Client

Send a stock quote request to Synapse over HTTP using the following command.

ant stockquote -Daddurl=http://localhost:8280/services/StockQuoteProxy -Dsymbol=MSFT

The proxy service will send the message to the JMS queue named SimpleStockQuoteService and wait for a response to arrive. In fact the JMS sender in Synapse will create a temporary queue to start polling on that queue for the response. The address of this queue will be sent on the request as a JMS header. Axis2 server will consumer the request from the queue and place a response on the temporary queue created by Synapse. At this point Synapse will pick up the response and forward it back to the Axis2 client over HTTP.

Back to Catalog