In this article we will look into invocation of Mule's file-inbound endpoint from Command Line Interface (CLI) using Linux CRUL command
Introduction
Recently I got the below requirement
Requirement
I need to pick up some files(multiple files) from a particular folder located in my hard drive. And then move those to some outbound process which can be FTP site or some other hard drive location. But this flow needs to be invoked from CLI.
The challenge is how can we achieve so?In this article we will look into as how this requirement has been handled.
What we need to have for doing the experiment?
We need
- Mule ESB
- Everything should be up and running properly
Let us start the experiment
In this case we will transfer the files from one location to another.Henceforth, let us create two folders (a) Input folder [ C:\InputFolder ] and (b) Output folder [ C:\OutputFolder ]
The "InputFolder" will have the below files in it initially
Now let us see the flow
We see that there are two flows "KickoffFlow" and "FileMovementFlow". The "KickoffFlow" invokes the "FileMovementFlow".Now let us see the cofiguration file
<flow name="FileMovementFlow" doc:name="filePickupFlow" initialState="stopped">
<file:inbound-endpoint path="C:\InputFolder" responseTimeout="10000" doc:name="Source"/>
<file:outbound-endpoint path="C:\OutputFolder" responseTimeout="10000" doc:name="Destination"/>
</flow>
<flow name="KickoffFlow" doc:name="flow2">
<http:inbound-endpoint address="http://localhost:8080/start" doc:name="HTTP" exchange-pattern="request-response"/>
<expression-component doc:name="InvokeFileMovementFlow">app.registry.FileMovementFlow.start();</expression-component>
<set-payload value="File Pickup successfully started" doc:name="Result"/>
</flow>
From the above image we can figure out that, initially we set the "initial" state property of "FileMovementFlow" Flow to "stopped" and this will make it stop unless something else is triggering it.
In the "KickoffFlow", the invocation will happen from the "Http" inbound endpoint.Once we pass the value "http://localhost:8080/start" in the CLI, then the "FileMovementFlow" will invoke by using app.registry.FileMovementFlow.start().
Finally, the files gets moved to the desired folder
Let us run the application.We will get the below screen
Now pass the value "http://localhost:8080/start" in the CLI and here is the output
Conclusion
So in this experiment we have seen as how to make a flow wait initially and then invoke it from another flow.Thanks for reading.