Friday, April 8, 2016

ActiveMQ - WSO2 ESB - Redelivery Delay - MaximumRedeliveries Configuration


There are use cases which we need to configure Redelivery Delay and the Maximum Redeliveries for Message Consumers of Activemq.

When consuming ActiveMq Queue, we can configure these parameters as mentioned in [1]

WSO2 ESB also can act as a message consumer and a message producer. Information of configuring that can be found in ESB documentation. [2]  Then we can find Consumer / Producer configurations in [3]

In ESB JMS proxy, we can configure Redelivery Delay and MaximumRedeliveries with using following parameters.

Eg:  By default Redelivery Delay in ActiveMq is one second and MaximumRedelivery count is 6. If you need to change the as bellow, you can do it with following parameters in the proxy service.

Redelivery Delay - 3 Seconds
MaximumRedelivery Count - 2


   <parameter name="redeliveryPolicy.maximumRedeliveries">2</parameter>
   <parameter name="transport.jms.SessionTransacted">true</parameter>
   <parameter name="redeliveryPolicy.redeliveryDelay">3000</parameter>
   <parameter name="transport.jms.CacheLevel">consumer</parameter>

Other than enabling the default configurations for JMS transport receiver, you dont need to add any other parameters to the axis2.xml to achive this.

Here is a sample proxy service which i have added above parameters.

Tested Versions : ESB 4.9.0 / Apache ActiveMQ 5.10.0


<proxy xmlns="http://ws.apache.org/ns/synapse"
       name="JMStoHTTPStockQuoteProxy"
       transports="jms"
       statistics="disable"
       trace="disable"
       startOnLoad="true">
    <target>
        <inSequence>
            <log level="full">
                <property name="Status" value=" Consuming the message"/>
                <property name="transactionID" expression="get-property('MessageID')"/>
            </log>
            <property name="SET_ROLLBACK_ONLY" value="true" scope="axis2"/>
            <drop/>
        </inSequence>
    </target>
    <parameter name="redeliveryPolicy.maximumRedeliveries">2</parameter>
    <parameter name="transport.jms.DestinationType">queue</parameter>
    <parameter name="transport.jms.SessionTransacted">true</parameter>
    <parameter name="transport.jms.Destination">JMStoHTTPStockQuoteProxy</parameter>
    <parameter name="redeliveryPolicy.redeliveryDelay">3000</parameter>
    <parameter name="transport.jms.CacheLevel">consumer</parameter>
    <description/>
</proxy>


When we configure these redelivery parameters, we need to make sure that we have enabled transactions for the proxy. We have done it using following parameter.

<parameter name="transport.jms.SessionTransacted">true</parameter>

Once we enable transactions, If the transaction is successful there is no redelivery happens.  So, in order to test the redelivery functionality, After consuming the message, we need to RollBack the transaction. In order to do that we need add following parameter inside the InSequence of the proxy service.


<property name="SET_ROLLBACK_ONLY" value="true" scope="axis2"/>

With above property, we notify the server that, The tranaction is Rollbacked.

All these properties are passed in to the server when we make the connection from ESB to the Message Broker. So, at that time we need to specify all these parameters.


[1] http://activemq.apache.org/redelivery-policy.html
[2] https://docs.wso2.com/display/ESB490/Configure+with+ActiveMQ
[3] https://docs.wso2.com/display/ESB490/ESB+as+a+JMS+Consumer



No comments:

Post a Comment