Apache Synapse

##### Main Menu

- Home
- Download
- History
- License
- Thanks
- Sponsorship
- Security

##### Documentation

- Installation Guide
- Quick Start Guide
- Samples Setup Guide
- Samples Catalog
- Configuration Language
- Mediators Catalog
- Transports Catalog
- Extending Synapse
- Upgrading
- Deployment
- Javadocs
- FAQ

##### Developer Resources

- Developer Guide
- Development Best Practices
- Release Process

##### Project Details

- Overview
- Mailing Lists
- Source Repository
- Issue Tracking
- Dependencies
- Project Team
- Project Summary

##### Previous Releases

- Version 1.2
- Version 1.1.1
- Version 1.1
- Version 1.0

## Sample 250:Introduction to Transport Switching - JMS to HTTP/S

<definitions xmlns="http://ws.apache.org/ns/synapse"> <proxy name="StockQuoteProxy" 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> <publishWSDL uri="file:repository/conf/sample/resources/proxy/sample_proxy_1.wsdl"/> <parameter name="transport.jms.ContentType"> <rules> <jmsProperty>contentType</jmsProperty> <default>application/xml</default> </rules> </parameter> </proxy> </definitions>

### Objective

Demonstrate the ability of Synapse to perform transport switching (i.e. receiving messages over one transport and forwarding them over a different transport)

### Pre-requisites

- Deploy the SimpleStockQuoteService in the sample Axis2 server and start Axis2
- 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 Synapse (Refer JMS setup guide for more details)
- Start Synapse using the configuration numbered 250 (repository/conf/sample/synapse_sample_250.xml)
  Unix/Linux: sh synapse.sh -sample 250
  Windows: synapse.bat -sample 250

### Executing the Client

In this sample we are using a proxy service exposed over JMS (note the transports=jms attribute). If you check the WSDL of the proxy service using a web browser you will notice that it only has JMS endpoints.

Run the sample JMS client by switching to the samples/axis2Client directory and executing the following command.

ant jmsclient -Djms_type=pox -Djms_dest=dynamicQueues/StockQuoteProxy -Djms_payload=MSFT

This will send a plain XML formatted place order request to a JMS queue named 'StockQuoteProxy'. Synapse will be polling on this queue for any incoming messages so it will pick up the request. If you run Synapse in the DEBUG mode, following entry will be printed on the console.

[JMSWorker-1] DEBUG ProxyServiceMessageReceiver -Proxy Service StockQuoteProxy received a new message...

Then Synapse will mediate the request through the service bus and forward it to the sample Axis2 server over HTTP. Axis2 server will print the following entry on the console when it receives the request.

Accepted order for : 16517 stocks of MSFT at $ 169.14622538721846

Note that the operation is out-only and no response is sent back to the client. The transport.jms.ContentType property is necessary to allow the JMS transport to determine the content type of incoming messages. With the given configuration it will first try to read the content type from the 'contentType' message property and fall back to 'application/xml' (i.e. POX) if this property is not set. Note that the JMS client used in this example doesn't send any content type information.

It is also important to note that the name of the source JMS queue is same as the name of the proxy service (StockQuoteProxy). This is the default behavior of Synapse. Each proxy service by default listens on a JMS queue which has the same name as the service. It is possible to instruct a JMS proxy service to listen to an already existing destination without creating a new one. To do this, use the parameter elements on the proxy service definition to specify the destination and connection factory information. An example is given below.

<parameter name="transport.jms.Destination">dynamicTopics/something.TestTopic</parameter>

With the above parameter in the proxy configuration, proxy service will listen on a JMS topic named 'something.TestTopic' for incoming requests.

Back to Catalog