How can Apache Camel be used to monitor file changes?

后端 未结 5 1778
孤街浪徒
孤街浪徒 2020-12-10 02:09

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

5条回答
  •  半阙折子戏
    2020-12-10 02:31

    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: https://camel.apache.org/components/latest/file-component.html

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

    So something alike

    from("file:/somedir?noop=true&idempotentKey=${file:name}-${file:size}")
    

    Or

    from("file:/somedir?noop=true&idempotentKey=${file:name}-${file:modified}")
    

    You can read here about the various ${file:xxx} tokens you can use: http://camel.apache.org/file-language.html

提交回复
热议问题