How to Use a RabbitMQ Message Store¶
In this example, the client sends requests to a proxy service, which stores the messages in a RabbitMQ message store. The message forwarding processor then picks the stored messages from the RabbitMQ message store and invokes the back-end service.
Synapse configurations¶
Following are the artifact configurations that we can use to implement this scenario. See the instructions on how to build and run this example.
<?xml version="1.0" encoding="UTF-8"?>
<messageStore class="org.apache.synapse.message.store.impl.rabbitmq.RabbitMQStore" name="rabbitmq" xmlns="http://ws.apache.org/ns/synapse">
<parameter name="store.rabbitmq.host.name">localhost</parameter>
<parameter name="store.producer.guaranteed.delivery.enable">false</parameter>
<parameter name="store.rabbitmq.host.port">5672</parameter>
<parameter name="store.rabbitmq.route.key"/>
<parameter name="store.rabbitmq.username"/>
<parameter name="store.rabbitmq.virtual.host"/>
<parameter name="rabbitmq.connection.ssl.enabled">false</parameter>
<parameter name="store.rabbitmq.exchange.name"/>
<parameter name="store.rabbitmq.queue.name">xyz</parameter>
<parameter name="store.rabbitmq.password"/>
</messageStore>
<endpoint xmlns="http://ws.apache.org/ns/synapse" name="SimpleStockQuoteService">
<address uri="http://127.0.0.1:9000/services/SimpleStockQuoteService"/>
</endpoint>
<proxy xmlns="http://ws.apache.org/ns/synapse" name="Proxy1" transports="https http" startOnLoad="true" trace="disable">
<target>
<inSequence>
<property name="FORCE_SC_ACCEPTED" value="true" scope="axis2"/>
<property name="OUT_ONLY" value="true"/>
<log level="full"/>
<store messageStore="rabbitmq"/>
</inSequence>
</target>
</proxy>
<messageProcessor xmlns="http://ws.apache.org/ns/synapse" class="org.apache.synapse.message.processor.impl.forwarder.ScheduledMessageForwardingProcessor" name="Processor1" targetEndpoint="SimpleStockQuoteService" messageStore="rabbitmq">
<parameter name="max.delivery.attempts">4</parameter>
<parameter name="interval">4000</parameter>
<parameter name="is.active">true</parameter>
</messageProcessor>
See the descriptions of the above configurations:
Artifact | Description |
---|---|
Message Store | The RabbitMQ message store. |
Endpoint | Define an endpoint which is used to send the message to the back-end service. |
Proxy Service | Create a proxy service which stores messages to the created Message Store. Note that you can use the FORCE_SC_ACCEPTED property in the message flow to send an Http 202 status to the client after the Micro Integrator accepts a message. If this property is not specified, the client that sends the request to the proxy service will timeout since it isbnot getting any response back from the proxy. |
Message Processor | Create a message forwarding processor using the below configuration. Message forwarding processor consumes the messages stored in the message store. |
Build and run¶
Configure the RabbitMQ broker with the Micro Integrator.
Create the artifacts:
-
Launch Visual Studio Code with the Micro Integrator for VS Code extension (MI for VS Code) installed.
Info
Follow the Install Micro Integrator for VS Code documentation for a complete installation guide.
-
Create an integration project.
- Create the proxy service, endpoint, and message processor with the configurations given above.
- Deploy the artifacts in your Micro Integrator.
Set up the back-end service:
- Download the back-end service.
- Extract the downloaded zip file.
- Open a terminal, navigate to the
axis2Server/bin/
directory inside the extracted folder. -
Execute the following command to start the axis2server with the SimpleStockQuote back-end service:
sh axis2server.sh
axis2server.bat
Invoke the service:
POST http://localhost:8290/services/Proxy1 HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: text/xml;charset=UTF-8
SOAPAction: "urn:getQuote"
Content-Length: 492
Host: localhost:8290
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://services.samples" xmlns:xsd="http://services.samples/xsd">
<soapenv:Header/>
<soapenv:Body>
<ser:getQuote xmlns:ser="http://services.samples" xmlns:xsd="http://services.samples/xsd">
<ser:request>
<xsd:symbol>IBM</xsd:symbol>
</ser:request>
</ser:getQuote>
</soapenv:Body>
</soapenv:Envelope>
Note a message similar to the following example:
SimpleStockQuoteService :: Accepted order for : 7482 stocks of IBM at $ 169.27205579038733