Store and forward messages with wso2 Enterprice Service Bus


In this blog post I discuss the scenario of store and forward with jms message store. For this post I will use the wso2esb-4.8.0  and apache activemq.

With the store and forward scenario, when a message comes to a proxy service, the message is stored in the message store by the proxy service and the message processor picks up the message and sends to the back end.

Before configuring the necessary message stores, proxies endpoints and processors, we need to configure the ESB to communicate with the activemq. Navigate to the axis2.xml available within <esb-home>/repository/conf/axis2 and uncomment the relevant transportReceiver

<!--Uncomment this and configure as appropriate for JMS transport support, after setting up your JMS environment (e.g. ActiveMQ)-->
    <transportReceiver name="jms" class="org.apache.axis2.transport.jms.JMSListener">
Also uncomment the transportSender related to jms messages senders 

  <!-- uncomment this and configure to use connection pools for sending messages -->
     <transportSender name="jms" class="org.apache.axis2.transport.jms.JMSSender"/>

Next, copy the following jars to <esb_home>/repository/components/lib

activemq-core-5.5.1.jar
geronimo-j2ee-management_1.1_spec-1.0.1.jar
geronimo-jms_1.1_spec-1.1.0.wso2v1.jar
geronimo-jms_1.1_spec-1.1.1.jar
hawtbuf-1.2.jar (if using activemq-5.8.0)

Now the initial configurations required for linking up wso2esb with activemq is completed. Next we need to configure the necessary options to store and forward the message to the back end service.

First lets create a basic proxy service as shown below in the code. As shown below the TestProxy calls the SimpleStockQuote endpoint and sore the message on the message store named JMSMS.

<proxy name="TestProxy" transports="https http" startOnLoad="true" trace="disable">  
  <target>
     <inSequence>
        <property name="FORCE_SC_ACCEPTED" value="true" scope="axis2"/>
        <property name="OUT_ONLY" value="true"/>
        <property name="target.endpoint" value="SimpleStockQuoteService"/>
        <log level="full"/>
        <store messageStore="JMSMS"/>
     </inSequence>
  </target>
</proxy>
The message store as shown below connects to the activemq through the <parameter name="java.naming.factory.initial"> and through the java.naming.provider.url
and point to the port 61616 in order to store the messages in a queue.

<messageStore xmlns="http://ws.apache.org/ns/synapse"
             class="org.wso2.carbon.message.store.persistence.jms.JMSMessageStore"
             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>

We also need to define an end point to forward the message to the back-end service. To achieve this create an endpoint as shown below and point to the SimpleStockQuoteService.

<endpoint name="SimpleStockQuoteService">
</endpoint>

We also need to configure a message forwarding processor that picks the messages stored in the queue and forwards the messages to the back end. To achieve this create a message processor as shown below:

<messageProcessor class="org.apache.synapse.message.processors.forward.ScheduledMessageForwardingProcessor" name="Processor1" messageStore="JMSMS">
   <parameter name="max.delivery.attempts">4</parameter>
   <parameter name="interval">4000</parameter>
</messageProcessor>
Once these configurations are set start the axis2Server available within <esb-home>/samples/axis2Server using the axis2Server.sh command and generate a message from a client such as SoapUI to the proxyservice. Check the activemq webbased console to determine if the messages are stored and forwarded from the queue.

Comments

  1. Note: The property FORCE_SC_ACCEPTED in the message flow is used to send an Http 202 status to the client after ESB accepts a message.

    ReplyDelete

Post a Comment