如何使用 Apache Camel 来监控文件更改? [英] How can Apache Camel be used to monitor file changes?

查看:34
本文介绍了如何使用 Apache Camel 来监控文件更改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想监视给定目录中的所有文件的更改,即更新的时间戳.对于使用文件组件的 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.

令人惊讶的是,没有类似的选项

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

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

参见避免多次读取同一个文件(幂等消费者)部分.并阅读有关 idempotent 和 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆