How to Use a JMS Message Store¶ See the examples given below. Example 1: Store and forward JMS messages¶ In this example, the client sends requests to a proxy service, which stores the messages in a JMS message store. The message forwarding processor then picks the stored messages from the JMS 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. Message StoreEndpointProxy ServiceMessage Processor <messageStore xmlns="http://ws.apache.org/ns/synapse" class="org.apache.synapse.message.store.impl.jms.JmsStore" name="JMSMS"> <parameter name="java.naming.factory.initial">org.apache.activemq.jndi.ActiveMQInitialContextFactory</parameter> <parameter name="java.naming.provider.url">tcp://localhost:61616</parameter> </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="JMSMS"/> </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="JMSMS"> <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 Set the value of the the java.naming.provider.url property to point to the jndi.propertiesfile. In this case, store.jms.destination> is a mandatory parameter. If you are using the WSO2 Message Broker, you need to create a q ueue named 'JMSMS' using the Message Broker (i.e., the value you specify for the store.jms.destination. 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 WSO2 Integrator: MI 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 (Example 1)¶ Configure the ActiveMQ broker and set up the JMS Sender. Create the artifacts: Launch Visual Studio Code with the WSO2 Integrator: MI for VS Code extension (MI for VS Code) installed. Info Follow the Install WSO2 Integrator: MI 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 WSO2 Integrator: MI. 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: On MacOS/LinuxOn Windows 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> You can observe the following log on the back-end server: Mon Jul 08 14:27:42 IST 2024 samples.services.SimpleStockQuoteService :: Generating quote for : IBM Example 2: Using a reply sequence to process response¶ In the sample, when the message forwarding processor receives a response from the back-end service, it forwards it to a replySequence to process the response message. 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. Proxy ServiceMessage StoreMessage ProcessorSequenceEndpoint <proxy name="Proxy2" xmlns="http://ws.apache.org/ns/synapse" transports="https,http" statistics="disable" trace="disable" startOnLoad="true"> <target> <inSequence> <property name="FORCE_SC_ACCEPTED" value="true" scope="axis2" /> <log level="full" /> <store messageStore="JMSMS" /> </inSequence> </target> </proxy> <messageStore xmlns="http://ws.apache.org/ns/synapse" class="org.apache.synapse.message.store.impl.jms.JmsStore" name="JMSMS"> <parameter name="java.naming.factory.initial">org.apache.activemq.jndi.ActiveMQInitialContextFactory</parameter> <parameter name="java.naming.provider.url">tcp://localhost:61616</parameter> </messageStore> <messageProcessor name="Processor2" class="org.apache.synapse.message.processor.impl.forwarder.ScheduledMessageForwardingProcessor" targetEndpoint="SimpleStockQuoteService" messageStore="JMSMS" xmlns="http://ws.apache.org/ns/synapse"> <parameter name="interval">1000</parameter> <parameter name="client.retry.interval">1000</parameter> <parameter name="max.delivery.attempts">4</parameter> <parameter name="message.processor.reply.sequence">replySequence</parameter> <parameter name="is.active">true</parameter> <parameter name="max.delivery.drop">Disabled</parameter> <parameter name="member.count">1</parameter> </messageProcessor> <sequence xmlns="http://ws.apache.org/ns/synapse" name="replySequence"> <log level="full"> <property name="REPLY" value="MESSAGE" /> </log> </sequence> <endpoint xmlns="http://ws.apache.org/ns/synapse" name="SimpleStockQuoteService"> <address uri="http://127.0.0.1:9000/services/SimpleStockQuoteService"/> </endpoint> See the descriptions of the above configurations: Artifact Description Message Store Set the value of the the java.naming.provider.url property to point to the jndi.propertiesfile. In this case, store.jms.destination> is a mandatory parameter. If you are using the WSO2 Message Broker, you need to create a q ueue named 'JMSMS' using the Message Broker (i.e., the value you specify for the store.jms.destination. 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. Sequence Create a sequence to handle the response received from the back-end service. Message Processor Create a message forwarding processor using the below configuration. Message forwarding processor consumes the messages stored in the message store. Compared to [Example 1](#example-1), this has an additional parameter **message.processor.reply.sequence** to point to a sequence to handle the response message. Build and run (Example 2)¶ Configure the ActiveMQ broker. Create the artifacts: Launch Visual Studio Code with the WSO2 Integrator: MI for VS Code extension (MI for VS Code) installed. Info Follow the Install WSO2 Integrator: MI for VS Code documentation for a complete installation guide. Create an integration project. Create the proxy service, mediation sequences, endpoint, message store and message processor with the configurations given above. Deploy the artifacts in your WSO2 Integrator: MI. 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: On MacOS/LinuxOn Windows sh axis2server.sh axis2server.bat Invoke the service using the request provided above. You will see a message similar to the following example printed in the backend service.