Sample 269:Introduction to AMQP Transport

<definitions xmlns="http://ws.apache.org/ns/synapse"> <proxy name="ConsumerProxy" transports="amqp"> <target> <inSequence> <property action="set" name="OUT_ONLY" value="true"/> <log level="custom"> <property name="status" value="At ConsumerProxy"/> </log> <log level="full"/> <drop/> </inSequence> <outSequence> <send/> </outSequence> </target> <publishWSDL uri="file:repository/conf/sample/resources/proxy/sample_proxy_1.wsdl"/> <parameter name="transport.amqp.ConnectionFactoryName">consumer</parameter> <parameter name="transport.amqp.QueueName">ConsumerProxy</parameter> </proxy> </definitions>

Objective

Demonstrate the AMQP transport of Synapse.

Pre-requisites

  • Download the RabbitMQ Java client library and copy it into Synapse class path (SYNAPSE_HOME/lib).
  • Download and install the RabbitMQ AMQP broker. Then start the broker on its default port(5672).
  • Uncomment the AMQP transport listener section in axis2.xml(repository/conf/axis2.xml). If you are running the AMQP broker on a port other than the default port, configure the connection factory definitions in AMQP transport listener appropriately.
  • Start Synapse using the configuration numbered 269 (repository/conf/sample/synapse_sample_269.xml)
    Unix/Linux: sh synapse.sh -sample 269
    Windows: synapse.bat -sample 269

Executing the Client

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

Run the sample RabbitMQ AMQP client by switching to the samples/axis2Client directory and executing the following command. Other options that can be passed into the RabbitMQ client can be found by just executing 'ant'.

ant rabbitmqclient -Damqpmode=producer -DqueueName=ConsumerProxy -DpayLoad=IBM

This will send a plain XML formatted place order request to a queue in the RabbitMQ broker. The queue is named 'ConsumerProxy'. Synapse will be polling on this queue for any incoming messages so it will pick up the request. A message similar to following will be logged on the console indicating that the message has been received at the proxy service.

2013-07-30 17:00:56,687 [-] [pool-11-thread-5] INFO LogMediator status = At ConsumerProxy
22013-07-30 17:00:56,688 [-] [pool-11-thread-5] INFO LogMediator To: null, Direction: request, Envelope: <?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><m:placeOrder xmlns:m="http://services.samples"> <m:order> <m:price>163.00923364424872</m:price> <m:quantity>6620</m:quantity> <m:symbol>IBM</m:symbol> </m:order> </m:placeOrder></soapenv:Body></soapenv:Envelope>

Note that the operation is out-only and no response is sent back to the client. The content type of the message can be configured using the parameter transport.amqp.ContentType and by default this is assumed to be application/xml.

<parameter name="transport.amqp.ConnectionFactoryName">consumer</parameter>

Above parameter defines the name of the connection factory that should be used. If a specific connection factory is not given the default connection factory will be used.

<parameter name="transport.amqp.QueueName">ConsumerProxy</parameter>

Above parameter defines the queue to which the proxy service will connect and start to listen. The other configuration parameters and more examples of AMQP transport can be found in the AMQP transport documentation.

Back to Catalog