## Apache Synapse

## Sample 251: Switching from HTTP/S to JMS

<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="OUT_ONLY" value="true"/> </inSequence> <outSequence> <send/> </outSequence> </target> <publishWSDL uri="file:repository/conf/sample/resources/proxy/sample_proxy_1.wsdl"/> </proxy> </definitions>

### Objective

This sample demonstrates receiving messages over HTTP/S and forwarding them to a JMS queue

### 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 251 (repository/conf/sample/synapse_sample_251.xml)
  Unix/Linux: sh synapse.sh -sample 251
  Windows: synapse.bat -sample 251

### Executing the Client

This Synapse configuration creates a proxy service over HTTP and forwards received messages to a JMS queue. To test this functionality, send a place order request to Synapse over HTTP as follows.

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

Note that the target endpoint of the proxy service points to a JMS queue in the ActiveMQ broker.

jms:/SimpleStockQuoteService?transport.jms.ConnectionFactoryJNDIName= QueueConnectionFactory&java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory& java.naming.provider.url=tcp://localhost:61616

The sample Axis2 server will pick up the message from the JMS queue and print the following log entry.

Accepted order for : 18406 stocks of MSFT at $ 83.58806051152119

Back to Catalog