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="" xmlns:scripting="" xmlns:http="" xmlns:metadata="" xmlns:dw="" xmlns:db="" xmlns:batch="" xmlns:sfdc="" xmlns:tracking="" xmlns="" xmlns:doc=""

<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>


payload = new java.util.ArrayList();
<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:inbound-endpoint exchange-pattern="one-way" path="aggregated_download_tour_vm" doc:name="VM">
<collection-aggregator />
<logger message="COMPLETED EXAMPLE" level="INFO"/>
<logger message="No Record To Process" level="INFO"/>



<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>

Post comments and suggestions .!!

Back to Featured Articles on Logo Paperblog