Computing Magazine

How to Make Poller Component Efficient In MULE ESB

Posted on the 09 June 2017 by Abhishek Somani @somaniabhi
Poller in MULE ESB is a very important component when you want to keep polling a endpoint for changes and then process it . Most of the times we do not know how big the changes will be and how much time will it take to complete . So setting polling interval becomes very crucial , because you do not want to trigger a new process before completing the existing task , and also you do not want to lose too much time waiting for the next trigger , if you complete the process earlier . Following code snippet solves your problem , it achieves synchronous behavior and poller will wait if the process is taking some time , it also achieves asynchornous efficiency where if you have 10 results then 10 separate process will be executed and main poller flow will still wait for them to complete . Code is self explanatory , i have used simple request reply and aggregator pattern , hope it helps .

<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:vm="http://www.mulesoft.org/schema/mule/vm" xmlns:scripting="http://www.mulesoft.org/schema/mule/scripting" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:metadata="http://www.mulesoft.org/schema/mule/metadata" xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw" xmlns:db="http://www.mulesoft.org/schema/mule/db" xmlns:batch="http://www.mulesoft.org/schema/mule/batch" xmlns:sfdc="http://www.mulesoft.org/schema/mule/sfdc" xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.mulesoft.org/schema/mule/vm http://www.mulesoft.org/schema/mule/vm/current/mule-vm.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd
http://www.mulesoft.org/schema/mule/db http://www.mulesoft.org/schema/mule/db/current/mule-db.xsd
http://www.mulesoft.org/schema/mule/sfdc http://www.mulesoft.org/schema/mule/sfdc/current/mule-sfdc.xsd
http://www.mulesoft.org/schema/mule/batch http://www.mulesoft.org/schema/mule/batch/current/mule-batch.xsd
http://www.mulesoft.org/schema/mule/ee/dw http://www.mulesoft.org/schema/mule/ee/dw/current/dw.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/scripting http://www.mulesoft.org/schema/mule/scripting/current/mule-scripting.xsd">



<flow name="exampleFlow" processingStrategy="synchronous" >

<poll doc:name="Poll" >
<fixed-frequency-scheduler frequency="10000" timeUnit="MILLISECONDS"></fixed-frequency-scheduler>
<logger message="Upload tour poll started" level="DEBUG"></logger>

</poll>

<expression-component>
payload = new java.util.ArrayList();
payload.add("test");
payload.add("test2");
</expression-component>
<choice >
<when expression="#[payload.size() >0]">
<request-reply doc:name="Request-Reply" >
<vm:outbound-endpoint exchange-pattern="one-way" path="download_tour_vm" doc:name="VM">
<collection-splitter />
</vm:outbound-endpoint>
<vm:inbound-endpoint exchange-pattern="one-way" path="aggregated_download_tour_vm" doc:name="VM">
<collection-aggregator />
</vm:inbound-endpoint>
</request-reply>
<logger message="COMPLETED EXAMPLE" level="INFO"/>
</when>
<otherwise>
<logger message="No Record To Process" level="INFO"/>
</otherwise>

</choice>

</flow>






<flow name="downloadTour">
<vm:inbound-endpoint path="download_tour_vm" doc:name="VM"/>

<scripting:component doc:name="Groovy">
<scripting:script engine="Groovy"><![CDATA[sleep(20000);
return message.payload;]]></scripting:script>
</scripting:component>
</flow>

</mule>
Post comments and suggestions .!!

Back to Featured Articles on Logo Paperblog

Magazines