Thursday, June 27, 2013

JMS Transaction with retries to the destination ( Workaround solution for ScheduleMessageProcessor without Order Delivery) ESB 4.6.0 with ActiveMQ

  Following sample will describe how you can use JMSTrasaction support and allow message to be redelivery for few time  (as how it configured in axis2.xml) then if failed move the given message to DeadLetter Queue in ActiveMQ, 

 <proxy name="StockQuoteProxy" transports="jms" startOnLoad="true">
      <target>
         <inSequence>
            <property name="OUT_ONLY" value="true"/>
            <callout serviceURL="http://localhost:9000/services/SimpleStockQuoteService">
               <source type="envelope"/>
               <target key="placeOrder"/>
            </callout>
            <log level="custom">
               <property name="Transaction Action" value="Committed"/>
            </log>
         </inSequence>
         <faultSequence>
            <property name="SET_ROLLBACK_ONLY" value="true" scope="axis2"/>
            <log level="custom">
               <property name="Transaction Action" value="Rollbacked"/>
            </log>
         </faultSequence>
      </target>
      <parameter name="transport.jms.ContentType">
         <rules>
            <jmsProperty>contentType</jmsProperty>
            <default>application/xml</default>
         </rules>
      </parameter>
      <parameter name="transport.jms.ConnectionFactory">myQueueConnectionFactory</parameter>
      <parameter name="transport.jms.DestinationType">queue</parameter>
   </proxy>

 You need to add following paramters to the axis2.xml under ESB_HOME/repository/conf/axis/

  <parameter name="myQueueConnectionFactory" locked="false">
<parameter name="java.naming.factory.initial" locked="false">org.apache.activemq.jndi.ActiveMQInitialContextFactory</parameter>
<parameter name="java.naming.provider.url" locked="false">tcp://localhost:61616</parameter>
<parameter name="transport.jms.ConnectionFactoryJNDIName" locked="false">QueueConnectionFactory</parameter>
<parameter name="transport.jms.ConnectionFactoryType" locked="false">queue</parameter>
<parameter name="transport.jms.ConcurrentConsumers" locked="false">50</parameter>
<parameter name="transport.jms.MaxConcurrentConsumers" locked="false">50</parameter>
                <parameter name="transport.jms.SessionTransacted">true</parameter>
                <parameter name="transport.jms.SessionAcknowledgement" locked="true">CLIENT_ACKNOWLEDGE</parameter>    
  <parameter name="redeliveryPolicy.maximumRedeliveries" locked="true">-1</parameter>
<parameter name="redeliveryPolicy.redeliveryDelay" locked="true">2000</parameter>
<parameter name="transport.jms.CacheLevel">consumer</parameter>
</parameter>


You may required to add following jar to ESB 4.6.0 as patch https://www.dropbox.com/s/3u1agai803vt2cw/axis2-transport-jms_1.1.0.wso2v7.jar

No comments:

Post a Comment