Process files one after another

Facebooktwittergoogle_plusredditpinterestlinkedinmail

Have you ever thought of processing multiple file sequentially through File endpoint in Mule ??
Generally in a scenario where multiple files exists in the inbound folder, all the files tends to move out together through the file inbound endpoint using multiple thread.

So, how can we restrict the files in a inbound folder where multiple files exists , to process is a sequential manner , that is the files should be picked one by one and will be dispatched one by one in outbound folder ??

How to move file one after another sequentially ?

Let us consider we designed a flow, a file inbound to pick the file and a file outbound to dispatch the file to outbound folder.
Now the reason I kept a Groovy component is to slow the file processing in the flow. I have used sleep() method in the Groovy script to slow down this process, so that it is visible to us when the file is being settled or deposited in outbound folder.

Untitled

Now, to configure our file inbound to pick one file at a time is to make the flow processingStrategy=”synchronous”.

So, our Mule config will be as follows :-

Untitled

You can see that the inbound endpoint is picking the file from the location :- E:\backup\test and putting it into the location E:\backup\test\newfolder 

You can also see that in Groovy component there we implemented sleep(6000) method, so that it slow down the file movement by 6000 ms.

Testing our application

Now, let’s start out Mule application and deploy it in the server.
Let’s keep 5 files in the inbound location as below :-

Untitled

You can see there are 4 file present :- file1.txt, file2.txt, file3.txt, file4.txt
in the inbound location as above.

Now, if we move to the outbound location E:\backup\test\newfolder , we will find files are getting dispatched one by one as below :-

1

Here file1.txt is deposited first.

1

After few millisecond file2.txt is deposited in the same location.

1

Now file3.txt is deposited in the same location.

1

At the end finally file4.txt get dispatched in the same location.

So, you can see all the file has been dispatched one by one in the location.

Conclusion

So, whenever you need to process one file after another in a sequential manner with file inbound, just configure the flow
processingStrategy=”synchronous“

And that’s it .. The files will be processed one after another sequentially !!!

Hope, you liked this post.

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

2 Responses

  1. Anonymous Coward says:

    This is not the case in a clustered Mule environment.

Leave a Reply to Anonymous Coward Cancel 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>