如何使用Apache Camel监视文件更改? [英] How can Apache Camel be used to monitor file changes?
问题描述
我想监视给定目录中的所有文件的更改,即更新的时间戳.对于使用文件组件的Camel来说,这种用例似乎很自然,但是我似乎找不到找到配置此行为的方法.
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.
类似的uri:
file:/some/directory
将使用提供的目录中的文件,但将其删除.
will consume the files in the provided directory but will delete them.
类似的uri:
file:/some/directory?noop=true
在添加文件或启动路由时,每个文件都会使用一次.
consumes each file once when it is added or when the route is started.
令人惊讶的是,
consumeOnChange=true
是否有一种直接的方法来监视文件更改并且在使用后不删除文件?
Is there a straightforward way to monitor file changes and not delete the file after consuming?
推荐答案
您可以通过设置idempotentKey来告诉Camel如何将文件视为已更改来进行此操作.例如,如果文件大小更改或时间戳更改等.
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.
在Camel文件文档中查看更多详细信息: https://camel .apache.org/components/latest/file-component.html
See more details at the Camel file documentation at: https://camel.apache.org/components/latest/file-component.html
请参阅避免多次读取同一文件(幂等的使用者).并了解等幂和idempotentKey.
See the section Avoiding reading the same file more than once (idempotent consumer). And read about idempotent and idempotentKey.
类似的东西
from("file:/somedir?noop=true&idempotentKey=${file:name}-${file:size}")
或
from("file:/somedir?noop=true&idempotentKey=${file:name}-${file:modified}")
您可以在此处阅读有关可以使用的各种$ {file:xxx}令牌的信息: http ://camel.apache.org/file-language.html
You can read here about the various ${file:xxx} tokens you can use: http://camel.apache.org/file-language.html
这篇关于如何使用Apache Camel监视文件更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!