Apache Camel ftp consumer loads the same files again and again

穿精又带淫゛_ 提交于 2019-12-03 04:33:31

You need to use a persistent idempotent repository if you want Camel to be able to remember which files it previously have downloaded, between restarts.

You need to set this option on the ftp endpoint: idempotentRepository

See more details here: http://camel.apache.org/file2 (Note: The FTP component inherits the options from the file component.)

There are some examples on the wiki page how to use different stores. And you can also build you custom store.

Finally I end up with following solution:

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");
    }
}

Maybe @endryha answer work well in 2011, but not with Camel 2.20.1

In Camel 2.20.1, these code will create two idempotentRepository

  1. ftp default memory idempotentRepository
  2. idempotentConsumer custom idempotentRepository(file based in this case)

So the correct way to use idempotentRepository is (I remove most parameter for readability)

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

and a Bean

@Bean
private IdempotentRepository<String> myIdempotentRepo() {
    return FileIdempotentRepository.fileIdempotentRepository(new File("data", "repo.dat");
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!