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

查看:26
本文介绍了如何使用 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天全站免登陆