Holding your Mule

Facebooktwittergoogle_plusredditpinterestlinkedinmail

We generally design our complex  Mule flows for different functionalities. And in that design and implementation, 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.

But how can we use Sleep method in Mule??

Let us consider we have a following Mule flow :-

Untitled

 

Now you can see in the above flow the File inbound endpoint will pick 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 ???

We can surely achieve it by using Thread.sleep() method in a Java class. But here we will keep it simple.

We will be just using a Groovy component  instead of a Java class. The Groovy component is the ideal versatile tool to fall back on for these cases.

groovy

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

fl1

So as you can see, this Groovy component in the middle will be holding the payload for some time. The corresponding Mule flow will be :-

fl2

 

Here you can easily see that we have implemented sleep() method in the Groovy script with an interval of 3000 ms.

Testing our application

Now, we are done with our coding and will deploy our application and test it.

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

lg

 

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

Conclusion

So, using a Groovy component will save you from writing a Java class and implement this Java functions. This is a simple way of holding a data transfer in the Mule flow for a particular interval of time.

This is a simple trick by which we can achieve all these functionality easily. The Groovy component is an important component in Mule flow, with which which we can do some other functionalities like configuring interceptors, build a request or even interacting with databases.

We will bring all those features on some other post.

That’s all !!! I hope you liked this !!!

 

Facebooktwittergoogle_plusredditpinterestlinkedinmail

Anirban Sen Chowdhary

Anirban Sen Chowdhary is an information technology professional currently working on Java/J2ee, Esb and Integration platform. For more information, please visit http://anirbansenchowdhary.com and you can also follow https://twitter.com/Anir37

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>