How can Apache Camel be used to monitor file changes?


I would like to monitor all of the files in a given directory for changes, ie an updated timestamp. This use case seems natural for Camel using the file component, but I can't seem to find a way to configure this behavior.

A uri like:


will consume the files in the provided directory but will delete them.

A uri like:


consumes each file once when it is added or when the route is started.

It's surprising that there isn't an option along the lines of


Is there a straightforward way to monitor file changes and not delete the file after consuming?

You can do this by setting up the idempotentKey to tell Camel how a file is considered changed. For example if the file size changes, or its timestamp changes etc.

See more details at the Camel file documentation at:

See the section Avoiding reading the same file more than once (idempotent consumer). And read about idempotent and idempotentKey.

So something alike




You can read here about the various ${file:xxx} tokens you can use: