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

Friday, June 21, 2013

LDAP - Apache Directory Studio: A Basic Tutorial

Following Link might be quite useful if anyone would like to configure LDAP with Apache Directory Studio.

http://krams915.blogspot.com/2011/01/ldap-apache-directory-studio-basic.html

JMS message store with weblogic ESB 4.6.0


To setup the JMS message store with weblogic, please follow the steps as mentioned below.

1. Set the transport receiver configuration as below in ESB_HOME/repository/conf/axis2/axis2.xml

   <transportReceiver name="jms" class="org.apache.axis2.transport.jms.JMSListener">
       <parameter name="myQueueConnectionFactory" locked="false">
               <parameter name="java.naming.factory.initial" locked="false">weblogic.jndi.WLInitialContextFactory</parameter>
               <parameter name="java.naming.provider.url" locked="false">t3://localhost:7001</parameter>
               <parameter name="transport.jms.ConnectionFactoryJNDIName" locked="false">jms/myconnectionFactory</parameter>
               <parameter name="transport.jms.ConnectionFactoryType" locked="false">queue</parameter>
               <parameter name="transport.jms.UserName" locked="false">weblogic</parameter>
               <parameter name="transport.jms.Password" locked="false">admin123</parameter>
       </parameter>
       <parameter name="default" locked="false">
               <parameter name="java.naming.factory.initial" locked="false">weblogic.jndi.WLInitialContextFactory</parameter>
               <parameter name="java.naming.provider.url" locked="false">t3://localhost:7001</parameter>
               <parameter name="transport.jms.ConnectionFactoryJNDIName" locked="false">jms/myconnectionFactory</parameter>
               <parameter name="transport.jms.ConnectionFactoryType" locked="false">queue</parameter>
               <parameter name="transport.jms.UserName" locked="false">weblogic</parameter>
               <parameter name="transport.jms.Password" locked="false">admin123</parameter>
       </parameter>
   </transportReceiver>

2. Create a queue connection factory named ‘myconnectionFactory’ with JNDI name ‘jms/myconnectionFactory’
3. Create queue named ‘wso2MessageQueue’ with JNDI name ‘jms/wso2MessageQueue’
4. Remove the following packages from the ‘wlfullclient.jar’ weblogic java clien.
  • javax.jms
  • javax.xml.namespace

5. Copy the wlfullclient.jar to repository/components/lib of the ESB
6. You need to apply a patch to the org.wso2.carbon.message.store jar. Copy the patched org.wso2.carbon.message.store_4.0.5.jar to repository/components/plugins
7. Start the server (Weblogic server should be running)
8. Create a message store using the ESB. The message-store parameters should be as follows.

<messageStore name="wso2MessageStore" class="org.wso2.carbon.message.store.persistence.jms.JMSMessageStore" xmlns="http://ws.apache.org/ns/synapse">
  <parameter name="java.naming.factory.initial">weblogic.jndi.WLInitialContextFactory</parameter>
  <parameter name="java.naming.provider.url">t3://localhost:7001</parameter>
  <parameter name="store.jms.destination">jms/wso2MessageQueue</parameter>
  <parameter name="store.jms.connection.factory">jms/myconnectionFactory</parameter>
  <parameter name="store.jms.username">weblogic</parameter>
  <parameter name="store.jms.password">admin123</parameter>
  <parameter name="store.jms.JMSSpecVersion">1.1</parameter>
  <parameter name="store.jms.cache.connection">false</parameter>
  <parameter name="store.jms.ConsumerReceiveTimeOut">300</parameter>
  <parameter name="vender.class.loader.enabled">false</parameter>
</messageStore>

9. Save the message store. This would query the JMS queue in weblogic for the queue size and the resulting list view would show the number of messages in the queue.
10. You can send messages to a queue using a proxy configuration similar to the following.

<proxy xmlns="http://ws.apache.org/ns/synapse" name="weblogicJmsStore" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">
  <target>
     <inSequence>
        <property name="FORCE_SC_ACCEPTED" value="true" scope="axis2"/>
        <property name="target.endpoint" value="SimpleStockQuoteService"/>
        <log level="full"/>
        <store messageStore="wso2MessageStore"/>
     </inSequence>
  </target>
  <description></description>
</proxy>

11. Send a message using the try this service for the proxy.
12. View the sent message via the message store UI of the ESB.

https://www.dropbox.com/s/cmwhewpm6asw5j6/org.wso2.carbon.message.store-4.0.5.jar

Thursday, June 20, 2013

VFS Filtering Message based on different Error conditions


<proxy xmlns="http://ws.apache.org/ns/synapse" name="XXX" transports="vfs" statistics="enable" trace="enable" startOnLoad="true">
   <target>
      <inSequence>
         <log level="full">
            <property name="Processing file" expression="$trp:FILE_NAME"/>
         </log>
         <property name="transport.vfs.ReplyFileName" expression="$trp:FILE_NAME" scope="transport"/>
         <property name="fileName" expression="$trp:FILE_NAME" scope="default"/>
         <enrich>
            <source type="body" clone="true"/>
            <target type="property" property="ORGINAL_MESSAGE"/>
         </enrich>
         <send>
            <endpoint>
               <address uri="http://localhost:8089/mockSimpleStockQuoteServiceSoap11Binding" format="soap11"/>
            </endpoint>
         </send>
      </inSequence>
      <outSequence>
         <filter xmlns:s12="http://www.w3.org/2003/05/soap-envelope" xmlns:ns="http://org.apache.synapse/xsd" xmlns:s11="http://schemas.xmlsoap.org/soap/envelope/" xpath="s11:Body/s11:Fault | s12:Body/s12:Fault">
            <then>
               <enrich>
                  <source type="property" clone="true" property="ORGINAL_MESSAGE"/>
                  <target type="body"/>
               </enrich>
               <log level="custom">
                  <property name="ERROR FTP  ##################" value="eeeeeee"/>
               </log>
               <property name="transport.vfs.ReplyFileName" expression="$ctx:fileName" scope="transport"/>
               <property name="OUT_ONLY" value="true"/>
               <send>
                  <endpoint>
                     <address uri="vfs:file:///home/dushan/onlinesupport/session7/BEBusinessServiceError"/>
                  </endpoint>
               </send>
            </then>
            <else>
               <drop/>
            </else>
         </filter>
      </outSequence>
      <faultSequence>
         <log level="full">
            <property name="MESSAGE" value="Executing default 'fault' sequence"/>
            <property name="ERROR_CODE" expression="get-property('ERROR_CODE')"/>
            <property name="ERROR_MESSAGE" expression="get-property('ERROR_MESSAGE')"/>
         </log>
         <enrich>
            <source type="property" clone="true" property="ORGINAL_MESSAGE"/>
            <target type="body"/>
         </enrich>
         <log level="custom">
            <property name="ERROR FTP  ##################" value="eeeeeee"/>
         </log>
         <property name="transport.vfs.ReplyFileName" expression="$ctx:fileName" scope="transport"/>
         <property name="OUT_ONLY" value="true"/>
         <send>
            <endpoint>
               <address uri="vfs:file:///home/dushan/onlinesupport/session7/BEConnectionfail"/>
            </endpoint>
         </send>
      </faultSequence>
   </target>
   <parameter name="transport.vfs.ActionAfterProcess">MOVE</parameter>
   <parameter name="transport.PollInterval">5</parameter>
   <parameter name="transport.vfs.FileURI">file:///home/dushan/onlinesupport/session7/in</parameter>
   <parameter name="transport.vfs.MoveAfterProcess">file:///home/dushan/onlinesupport/session7/out</parameter>
   <parameter name="transport.vfs.FailedRecordNextRetryDuration">1000</parameter>
   <parameter name="transport.vfs.MoveAfterFailure">file:///home/dushan/onlinesupport/session7/fail123</parameter>
   <parameter name="transport.vfs.Locking">false</parameter>
   <parameter name="transport.vfs.FileNamePattern">.*.xml</parameter>
   <parameter name="transport.vfs.ContentType">application/xml</parameter>
   <parameter name="transport.vfs.ActionAfterFailure">MOVE</parameter>
   <parameter name="transport.vfs.MaxRetryCount">2</parameter>
   <description>:)</description>
</proxy>