1
votes

I am wondering if mule file connector always polls the source directory, or if this behavior can be overridden.

I configured an end point to read a file from FTP location using file connector and then process it. But my requirement is that the file should be read only when requested, for example when endpoint is called from Java. By controlling this behavior I can call endpoint point at the end of day and read all files placed at source during the day.

But mule keeps on polling the source location and downloads the file as soon as it is placed at the source. I tried to see if I can achieve my desired behavior by service override, but it does not seem obvious that it is possible.

Is there a different way to read a file from the source or can polling behavior be overridden in mule?

3

3 Answers

3
votes

You can achieve this is by following approaches

  1. Use Poll Schedular with Cron Scheduler for picking file automatically at fixed time of the day.
  2. For manual triggering you can expose HTTP endpoint and pick files using mule-module-requester in your flow. Mule requester allows you to pick singe or multiple resources.

Hope this helps.

1
votes

With the pointer I received from @Jason and @anupambhusari, I was able to solve the issue I was facing. I am putting my mule flows below, hopping it will help others.

In below mule flow I was able call vm end point "fileReader" to download file from FTPserver and them copy it to local folder with the help of "CopyFile" flow.

<ftp:connector name="FTP_Connector" pollingFrequency="1000" validateConnections="true" doc:name="FTP"/>
<flow name="HTTP-RequestFlow">
<vm:inbound-endpoint exchange-pattern="request-response"  path="/fileReader" doc:name="vm"/>
<mulerequester:request resource="ftp://<username>:<password>@<host>:<port>/<FTP resource Path>/?FTP_Connector" doc:name="Mule Requester"/>
<flow-ref name="CopyFile" doc:name="Copy File"/>
/flow>
<flow name="CopyFile" >
<file:outbound-endpoint path="output" outputPattern="#[message.inboundProperties.'originalFilename']" responseTimeout="10000" doc:name="File"/>
<set-payload value="Got a File" doc:name="Set Payload"/>
<logger message="Copying files on local disk #[message.payload]" level="INFO"/>
</flow>
0
votes

If you can meet your requirement by setting the file polling for the end of the day and not having to trigger it through a Java program you can create a quartz job. See this question for a code example.