13
Simple Groovy example in Mule

Groovy in Mule

Embed Size (px)

Citation preview

Page 1: Groovy in Mule

Simple Groovy example in Mule

Page 2: Groovy 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 in Mule

But how can we use Sleep method in Mule??

.

Page 4: Groovy in Mule

Here I will show you how ……

Page 5: Groovy 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 in Mule

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

Page 7: Groovy in Mule

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

Page 8: Groovy in Mule

So our Mule flow will be now following :-

This Groovy component will be holding the payload for some time

Page 9: Groovy 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 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 in Mule

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

Page 12: Groovy in Mule

Hope you enjoyed the simple yet an amazing trick in Mule

Page 13: Groovy in Mule