13
GROOVY EXAMPLE IN MULE

Groovy example in mule

Embed Size (px)

Citation preview

Page 1: Groovy example in mule

GROOVY EXAMPLE IN MULE

Page 2: Groovy example in mule

WE OFTEN WANT TO STOP OUR FLOW FOR SOMETIME AND THEN WANT TO PROCESS IT AFTER AN INTERVAL OF TIME.IN JAVA WE CAN USE SLEEP METHOD TO HOLD OUR THREAD FOR A SPECIFIC PERIOD OF TIME

Page 3: Groovy example in mule

BUT HOW CAN WE USE SLEEP METHOD IN MULE??

.

Page 4: Groovy example in mule

Here I will show you how ……

Page 5: Groovy example in mule

Let us consider we have a following Mule flow :-

Now you can see in the above flow the inbound endpoint will pic a file from a location and put it into another location. But what if we want to hold the flow for sometime before it put the file in the outbound location ???How can we hold the file for an particular interval of time ???

Page 6: Groovy example in mule

Yes .. We can do it by using sleep method in our flow

Page 7: Groovy example in mule

So, we need Groovy component to implement sleep method:-

Page 8: Groovy example in mule

So our Mule flow will be now following :-

This Groovy component will be holding the payload for some time

Page 9: Groovy example in mule

The corresponding Mule flow will be :-<file:connector name="File_Global" autoDelete="true" outputAppend="true" streaming="true" validateConnections="true" doc:name="File"/>

<flow name="Flow1" doc:name="Flow1"> <file:inbound-endpoint path="E:\backup\test" responseTimeout="10000" doc:name="File" connector-ref="File_Global"> <file:filename-regex-filter pattern="abc.txt" caseSensitive="false"/> </file:inbound-endpoint> <scripting:component doc:name="Groovy"> <scripting:script engine="Groovy"> <![CDATA[ sleep(3000); System.out.println("Holding the flow for 3000 ms"); return message.payload;]]> </scripting:script> </scripting:component> <file:outbound-endpoint path="E:\backup\test\newfolder" responseTimeout="10000" doc:name="File"/> </flow>

Page 10: Groovy example in mule

So, if we start our application again and put the inbound file in the location E:\backup\test , we will get the following in our console :-

Page 11: Groovy example in mule

And we will get the file in our outbound location E:\backup\test\newfolder after 3000 ms

Page 12: Groovy example in mule

Hope you enjoyed the simple yet an amazing trick in Mule

Page 13: Groovy example in mule

Thank You