<flow name="onNewFile">
<file:listener config-ref="file" directory="test-data/in" autoDelete="true">
<scheduling-strategy>
<fixed-frequency frequency="1000"/>
</scheduling-strategy>
</file:listener>
<flow-ref name="processFile" />
</flow>
To Trigger a Flow When a New File is Created or Modified
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.
Watermarking
For the File connector, the watermarking strategy can be used in two different modes: CREATION_TIMESTAMP
or MODIFIED_TIMESTAMP
. The strategy depends on whether you want to filter files based on their creation or modification time.
<file:listener doc:name="On New File"
config-ref="File_Config1"
watermarkMode="CREATED_TIMESTAMP">
<scheduling-strategy >
<fixed-frequency />
</scheduling-strategy>
</file:listener>
Repeatable Streams
The List operation makes use of the repeatable streams functionality introduced in Mule 4. The operation returns a list of messages, where each message represents a file in the list and holds a stream to the file. A stream is repeatable by default.
For more information, refer to Streaming in Mule 4.