>
Showing posts with label ESB. Show all posts
Showing posts with label ESB. Show all posts

Saturday, December 5, 2015

WSO2 ESB - Using File Inbound endpoint

With WSO2 ESB 4.9.0 you can use different Inbound endpoints. ESB has 3 types of inbound endpoints;
  • Listening Inbound Endpoints
  • Polling Inbound Endpoints
  • Event-Based Inbound Endpoints

In this blog post I'll explain how to create a file inbound endpoint.
File Inbound endpoint falls under Polling Inbound Endpoints. 

  1. Start ESB server.
  2. Go to Inbound Endpoints.
  3. Provide a name and select type as File. Click next.
  4. Provide and save the details here.


Sequence is the name of the sequence which should be called once a file is read from the location specified in transport.vfs. FileURI. You can read more on vfs parameters from [1]

Sample inbound endpoint configuration looks like follows,

<?xml version="1.0" encoding="UTF-8"?>
<inboundEndpoint xmlns="http://ws.apache.org/ns/synapse"
name="vfsEndpoint"
sequence="inboundtest"
onError="fault"
protocol="file"
suspend="false">
<parameters>
<parameter name="interval">60</parameter>
<parameter name="transport.vfs.ActionAfterErrors">NONE</parameter>
<parameter name="coordination">true</parameter>
<parameter name="transport.vfs.ContentType">application/xml</parameter>
<parameter name="transport.vfs.LockReleaseSameNode">false</parameter>
<parameter name="transport.vfs.AutoLockRelease">true</parameter>
<parameter name="transport.vfs.ActionAfterFailure">MOVE</parameter>
<parameter name="transport.vfs.AutoLockReleaseInterval">5000</parameter>
<parameter name="transport.vfs.CreateFolder">true</parameter>
<parameter name="sequential">true</parameter>
<parameter name="transport.vfs.ActionAfterProcess">MOVE</parameter>
<parameter name="transport.vfs.FileURI">file:///home/sachini/dev/inbooundtest</parameter>
<parameter name="transport.vfs.MoveAfterFailure">file:///home/sachini/dev/inbooundtest/error</parameter>
<parameter name="transport.vfs.DistributedLock">false</parameter>
<parameter name="transport.vfs.FileNamePattern">.*.xml</parameter>
<parameter name="transport.vfs.MoveAfterProcess">file:///home/sachini/dev/inbooundtest/out</parameter>
<parameter name="transport.vfs.Locking">enable</parameter>
<parameter name="transport.vfs.FileSortAscending">true</parameter>
<parameter name="transport.vfs.FileSortAttribute">NONE</parameter>
</parameters>
</inboundEndpoint>



Once you add the inbound endpoint and put a file (in this case a xml file) in the location specified in transport.vfs.FileURI. File will be read and the specified sequence will be called. 






Monday, October 26, 2015

WSO2 ESB unable to consume messages form JMS Queue


When there are large number of jms consumers in WSO2 ESB, you'll get a warning saying

"WARN {org.apache.axis2.transport.jms.JMSListener} -  Polling tasks on destination : testQueue of type queue for service test_ps have not yet started after 3 seconds ."


And the proxy service will not be able to consume the messages from the queue.

This is because there are not enough threads to consume messages from jms queues.You can increase the number threads used for jms transport  as mentioned below.

  • Create a file  jms.properties in <ESB_HOME> directory
  • Add the following properties to the created file
                      snd_t_core=200
                      snd_t_max=250

Tuesday, March 10, 2015

WSO2 ESB - Enrich Mediator

The Enrich Mediator can process a message based on a given source configuration and then perform the specified action on the message by using the target configuration. It is often used to do slight modifications to the payload.

This post explains some scenarios where Enrich mediator can be used.

Original payload

<orders>
<order>
<price>50.00</price>
<quantity>500</quantity>
<symbol>IBM</symbol>
<comment>REF 10053</comment>
</order>
<order>
<price>18.00</price>
<quantity>500</quantity>
<symbol>MSFT</symbol>
<comment>ref 20088398289</comment>
</order>
</orders>

Required payload-1

<orders>
<order>
<price>50.00</price>
<quantity>500</quantity>
<symbol>IBM</symbol>
<comment>REF 10053</comment>
</order>
<order>
<price>18.00</price>
<quantity>500</quantity>
<symbol>MSFT</symbol>
<comment>ref 20088398289</comment>
</order>
</orders>
<orderID>2</OrderID>

mediator

<property name="orderID" scope="default" description="orderID">
            <orderID xmlns="">2</orderID>
 </property>
  <enrich>
            <source clone="true" xpath="$ctx:orderID"/>
            <target action="sibling" xpath="//orders"/>
  </enrich>

Define a property <orderID>2</orderID>
Then add the property as a sibling of <orders>


Required payload-2

<orders>
<order>
<price>50.00</price>
<quantity>500</quantity>
<symbol>IBM</symbol>
<comment>REF 10053</comment>
</order>
<order>
<price>18.00</price>
<quantity>500</quantity>
<symbol>MSFT</symbol>
<comment>ref 20088398289</comment>
</order>
<orderID>2</OrderID>
</orders>

mediator

<property name="orderID" scope="default" description="orderID">
            <orderID xmlns="">2</orderID>
 </property>
   <enrich>
            <source clone="true" xpath="$ctx:orderID"/>
            <target action="child" xpath="//orders"/>
         </enrich>

Define a property <orderID>2</orderID>
Then add the property as a child of <orders>


Required payload-3

<orders>
<order>
<price>50.00</price>
<quantity>500</quantity>
<symbol>IBM</symbol>
<comment>REF 10053</comment>
<volume>100<volume>
</order>
<order>
<price>18.00</price>
<quantity>500</quantity>
<symbol>MSFT</symbol>
<comment>ref 20088398289</comment>
</order>
<orderID>2</OrderID>
</orders>

mediator

<property name="VOLUME" value="100"/>
 <enrich>
           <source type="inline" clone="true">
                   <volume xmlns=""/>
            </source>
            <target action="child" xpath="//orders/order"/>
 </enrich>
 <enrich>
            <source type="property" clone="true" property="VOLUME"/>
            <target xpath="//orders/order/volume"/>
 </enrich>

Using first enrich mediator we add the element <volume>  as a child of <order>
Second enrich mediator adds the value of “VOLUME” property to the newly created element



Required payload-4

<orders>
<order>
<price>50.00</price>
<quantity>500</quantity>
<symbol>IBM</symbol>
<comment>REF 10053</comment>
<volume>100<volume>
</order>
<order>
<price>18.00</price>
<quantity>500</quantity>
<symbol>MSFT</symbol>
<volume>100</volume>
<comment>ref 20088398289</comment>
</order>
<orderID>2</OrderID>
</orders>

mediator

 <property name="VOLUME" value="100"/>
 <enrich>
            <source type="inline" clone="true">
               <volume xmlns=""/>
            </source>
            <target action="child" xpath="//orders/order[symbol/text() = 'MSFT']"/>
  </enrich>
  <enrich>
            <source type="property" clone="true" property="VOLUME"/>
            <target xpath="//orders/order[symbol/text() = 'MSFT']/volume"/>
  </enrich>


Instead of comparing 'MSFT' twice,  we can use a property to store the value 'MSFT' and then use it for comparisons as below.
 <property name="VOLUME" value="100"/>
         <property name="SYMBOL" value="MSFT"/>
         <enrich>
            <source type="inline" clone="true">
               <volume xmlns=""/>
            </source>
            <target action="child"
                    xpath="//orders/order[symbol/text() = get-property('SYMBOL')]"/>
         </enrich>
         <enrich>
            <source type="property" clone="true" property="VOLUME"/>
            <target xpath="//orders/order[symbol/text() = get-property('SYMBOL')]/volume"/>
         </enrich>