Trigger a Flow When a New File Is Created or Modified Example - Mule 4
Anypoint Connectors for File, FTP, and SFTP provide an On New or Updated File operation that polls a directory for files that have been created or updated. A message is generated for each file that is found.
The following strategies determine that a file is new:
Set the Auto delete field to True to delete each file after it is processed, which causes all files obtained in the next poll to be considered new.
Set the Move to directory field to move each file to a different directory after it is processed, which achieves the same effect as Auto delete but without erasing the file.
Set the Watermark field to pick only files that have been created or updated after the last poll was executed.
You can also use a matcher for additional filtering of files.
To add and configure the On New or Updated File operation in Studio, follow these steps:
In the Mule Palette view, search for
sftpand select the On New or Updated File operation.
Drag the On New or Updated File operation onto the Studio canvas.
In the General tab of the operation configuration screen, click the plus sign (+) next to the Connector configuration field to access the global element configuration fields.
Specify the connection information and click OK.
Set the Directory field to the directory path on which pooled files are contained, for example,
Set the Auto delete field to True.
Select the Watermark field to enable watermarking.
The following screenshot shows the On New or Updated File operation configuration:
In the XML editor, the
<sftp:listener> configuration looks like this:
<flow name="onNewFile"> <sftp:listener config-ref="file" directory="test-data/in" autoDelete="true" watermarkEnabled="true"> <scheduling-strategy> <fixed-frequency frequency="1000"/> </scheduling-strategy> </sftp:listener> <flow-ref name="processFile" /> </flow>