Apache Camel ftp使用者一次又一次地加载相同的文件

我有以下弹簧配置

            

在ftp方面,我有3个文件夹,包含我要下载的文件。 我想实现以下场景:

  1. 在ftp上,第一个数据拉消费者将固定数量的文件(对于isntance 5)加载到目标文件夹
  2. 在第二次尝试加载文件时,ftp状态仍然相同(5个文件)和驼峰ftp消费者什么都不做(除了检查新文件)
  3. 要ftp到达新的2个文件,并在此数据拉消费者只下载这两个新文件

目前我的当前解决方案每次运行dataload进程时都会下载所有文件,我如何管理有关下载文件的信息以防止重复下载(我的意思是已经从ftp复制了文件),我可以编写自己的filter来过滤掉已下载的文件,但我相信应该有内置function,这将给我控制这个(也许是idempotentRepository,实际上我不确定)…

如果希望Camel能够记住以前在重新启动之间下载了哪些文件,则需要使用持久性幂等存储库。

您需要在ftp端点上设置此选项:idempotentRepository

请在此处查看更多详细信息: http : //camel.apache.org/file2 (注意:FTP组件从文件组件inheritance选项。)

维基页面上有一些示例如何使用不同的商店。 您还可以构建自定义商店。

最后我最终得到以下解决方案:

 public class SdiRouteBuilder extends RouteBuilder { @Override public void configure() throws Exception { from("ftp://login@url_to_ftp/RootFolder?" + "password=******&noop=true&stepwise=false&binary=true&consumer.delay=10s&recursive=true&filter=#fileFilter") .idempotentConsumer(header("CamelFileName"), FileIdempotentRepository.fileIdempotentRepository(new File("data", "repo.dat"))) .process(new DownloadLogger()) .to("file:data/outbox"); } } 

也许@endryha在2011年回答得很好,但不是Camel 2.20.1

在Camel 2.20.1中,这些代码将创建两个idempotentRepository

  1. ftp默认内存idempotentRepository
  2. idempotentConsumer自定义idempotentRepository(在这种情况下基于文件)

所以使用idempotentRepository的正确方法是(为了便于阅读,我删除了大多数参数)

 "ftp://login@url_to_ftp/RootFolder?&idempotent=true&idempotentRepository=#myIdempotentRepo" 

和一个豆

 @Bean private IdempotentRepository myIdempotentRepo() { return FileIdempotentRepository.fileIdempotentRepository(new File("data", "repo.dat"); }