我已经定义了以下骆驼路线:
RouteBuilder rb = new RouteBuilder() {
@Override
public void configure() throws Exception {
from("sftp://myhost//path/to/files/")
.to("log:loggingCategory?level=INFO")
.to("file:///tmp/");
}
};
当我使用此路由启动上下文时,camel会连接并下载文件。我的问题是,驼峰重复下载相同的文件,直到关闭上下文。为什么FTP2组件会这样做?如何阻止它?
我已经通过maven包含了camel-core和camel-ftp的2.10.4版本。
答案 0 :(得分:3)
Indempotent Consumer可以解决问题。 the FTP2 component的文档将the File2 component称为“因为此组件的所有选项也适用”。有一个参数“ indempotent = true ”可激活LRUCache的使用:
使用Idempotent Consumer EIP模式让Camel跳过的选项 已处理的文件。默认情况下会使用基于内存的LRUCache 持有1000个条目。如果noop = true,则将启用幂等 以及避免一遍又一遍地使用相同的文件。
我的完整源定义现在看起来像这样:
from("sftp://myhost//path/to/files/?username=user&password=secret&idempotent=true")
答案 1 :(得分:1)
来自camel ftp2文档:
默认情况下,FTP使用者将保持消耗的文件不变 远程FTP服务器。如果需要,您必须明确配置它 它删除文件或将它们移动到另一个位置。例如 您可以使用delete = true删除文件,或使用move = .done移动 将文件放入隐藏的子目录。
要删除文件,请将路线更改为
from("sftp://myhost//path/to/files?delete=true")
确保已连接的用户具有所需的权限。