How to Consume JMS Messages¶ This section describes how to configure WSO2 Integrator: MI to listen to a JMS Queue. Example 1: One-way messaging¶ In this example, the WSO2 Integrator: MI listens to a JMS queue, consumes messages, and sends them to an HTTP back-end service. Synapse configuration¶ Given below is the synapse configuration of the proxy service that mediates the above use case. Note that you need to update the JMS connection URL according to your broker as explained below. See the instructions on how to build and run this example. <proxy xmlns="http://ws.apache.org/ns/synapse" name="JMStoHTTPStockQuoteProxy" transports="jms" startOnLoad="true"> <target> <inSequence> <header name="Action" value="urn:getQuote"/> <property action="set" name="OUT_ONLY" value="true"/> <call> <endpoint> <address uri="http://localhost:9000/services/SimpleStockQuoteService"/> </endpoint> </call> </inSequence> </target> <parameter name="transport.jms.ConnectionFactory">myQueueConnectionFactory</parameter> <parameter name="transport.jms.ContentType"> <rules> <jmsProperty>contentType</jmsProperty> <default>text/xml</default> </rules> </parameter> </proxy> Note Make sure to configure the relevant JMS parameters in the deployment.toml file. [[transport.jms.listener]] name = "myQueueConnectionFactory" parameter.initial_naming_factory = "org.apache.activemq.jndi.ActiveMQInitialContextFactory" parameter.provider_url = "tcp://localhost:61616" parameter.connection_factory_name = "QueueConnectionFactory" parameter.connection_factory_type = "queue" The Synapse artifacts used are explained below. Artifact Type Description Proxy Service A proxy service is used to receive messages and to define the message flow. Header Mediator A header mediator is used to set the SOAPAction header. Property Mediator The OUT_ONLY property is set to true to indicate that message exchange is one-way. Endpoint Mediator To send a message to the HTTP backend, you should define the connection URL as the endpoint address. Build and run¶ 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 with the configurations given above. Deploy the artifacts in your WSO2 Integrator: MI. Set up the broker: Configure a broker with your WSO2 Integrator: MI instance. Let's use Active MQ for this example. Start the broker. Start the WSO2 Integrator: MI (after starting the broker). 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 You now have a running WSO2 Integrator: MI instance, ActiveMQ instance, and a sample back-end service to simulate the sample scenario. Add a message in the JMStoHTTPStockQuoteProxy queue with the following XML payload using ActiveMQ Web Console. <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> <ser:request> <xsd:symbol>IBM</xsd:symbol> </ser:request> </ser:getQuote> </soapenv:Body> </soapenv:Envelope> The WSO2 Integrator: MI will read the message from the ActiveMQ queue and send it to the back-end service. You will see the following response in the back-end service console: INFO [wso2/stockquote_service] - Stock quote service invoked. INFO [wso2/stockquote_service] - Generating getQuote response for IBM INFO [wso2/stockquote_service] - Stock quote generated. Info You can specify a different content type within the transport.jms.ContentType parameter. In the sample configuration above, the content type defined is text/xml. You can make the proxy service a JMS listener by setting its transport as jms. Once the JMS transport is enabled for a proxy service, the WSO2 Integrator: MI listens on a JMS queue for the same name as the proxy service.In the sample configuration above, the WSO2 Integrator: MI listens to a JMS queue named JMStoHTTPStockQuoteProxy. To make the proxy service listen to a different JMS queue, define the transport.jms.Destination parameter with the name of the destination queue. For more information, you can refer details of the JMS transport parameters used in the WSO2 Integrator: MI. Example 2: Two-way HTTP back-end call¶ In addition to one-way invocations, the proxy service can listen to the queue, pick up a message, and do a two-way HTTP call as well. It allows the response to be delivered to a queue specified by the client. This is done by specifying a ReplyDestination element when placing a request message to a JMS queue. Synapse configuration¶ We can have a proxy service similar to the following to simulate a two-way invocation. See the instructions on how to build and run this example. <proxy xmlns="http://ws.apache.org/ns/synapse" name="JMStoHTTPStockQuoteProxy1" transports="jms" startOnLoad="true" trace="disable"> <target> <inSequence> <header name="Action" value="urn:getQuote"/> <call> <endpoint> <address uri="http://localhost:9000/services/SimpleStockQuoteService"/> </endpoint> </call> <respond/> </inSequence> </target> <parameter name="transport.jms.ContentType"> <rules> <jmsProperty>contentType</jmsProperty> <default>text/xml</default> </rules> </parameter> <parameter name="transport.jms.ConnectionFactory">myQueueConnectionFactory</parameter> <parameter name="transport.jms.ReplyDestination">ResponseQueue</parameter> </proxy> The Synapse artifacts used are explained below. Artifact Type Description Proxy Service A proxy service is used to receive messages and to define the message flow. Header Mediator A header mediator is used to set the SOAPAction header. Call Mediator To send a message to the HTTP backend, you should define the connection URL as the endpoint address. Build and run¶ 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 with the configurations given above. Deploy the artifacts in your WSO2 Integrator: MI. Set up the broker: Configure a broker with your WSO2 Integrator: MI instance. Let's use Active MQ for this example. Start the broker. Start the WSO2 Integrator: MI (after starting the broker). 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 You now have a running WSO2 MI instance, an ActiveMQ instance, and a sample back-end service to simulate the sample scenario. Add a message in JMStoHTTPStockQuoteProxy1 queue with the following XML payload using the ActiveMQ Web Console. You can view the responses from the back-end service in the ResponseQueue. <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> <ser:request> <xsd:symbol>IBM</xsd:symbol> </ser:request> </ser:getQuote> </soapenv:Body> </soapenv:Envelope> Info You can make the proxy service a JMS listener by setting its transport as jms. Once the JMS transport is enabled for a proxy service, the WSO2 Integrator: MI listens on a JMS queue for the same name as the proxy service.In the sample configuration above, the WSO2 Integrator: MI listens to a JMS queue named JMStoHTTPStockQuoteProxy1. To make the proxy service listen to a different JMS queue, define the transport.jms.Destination parameter with the name of the destination queue. For more information, you can refer details of the JMS transport parameters used in the WSO2 Integrator: MI. Example 3: Set content type of incoming JMS messages¶ The WSO2 Integrator: MI considers all messages consumed from a queue as SOAP messages by default. To consider that the messages consumed from a queue are of a different format, define the transport.jms.ContentType parameter with the respective content type as a proxy service parameter. Synapse configuration¶ <proxy xmlns="http://ws.apache.org/ns/synapse" name="JMStoHTTPStockQuoteProxy" transports="jms"> <target> <inSequence> <header name="Action" value="urn:getQuote"/> <property action="set" name="OUT_ONLY" value="true"/> <call> <endpoint> <address uri="http://localhost:9000/services/SimpleStockQuoteService"/> </endpoint> </call> </inSequence> </target> <parameter name="transport.jms.ContentType"> <rules> <jmsProperty>contentType</jmsProperty> <default>application/xml</default> </rules> </parameter> <parameter name="transport.jms.Destination">MyJMSQueue</parameter> </proxy> The Synapse artifacts used are explained below. Artifact Type Description Proxy Service A proxy service is used to receive messages and to define the message flow. Header Mediator A header mediator is used to set the SOAPAction header. Call Mediator To send a message to the HTTP backend, you should define the connection URL as the endpoint address. Info You can specify a different content type within the transport.jms.ContentType parameter. In the sample configuration above, the content type defined is application/xml. If you want the proxy service to listen to a queue where the queue name is different from the proxy service name, you can specify the queue name using the transport.jms.Destination parameter. In the sample configuration above, the WSO2 Integrator: MI listens to a JMS queue named MyJMSQueue. For more information, you can refer details of the JMS transport parameters used in the WSO2 Integrator: MI.