从 sftp 文件夹下载所有文件后关闭 sftp camel 路由

Shutdown sftp camel route after downloading all files from sftp folder

我正在开发一个 spring-boot 应用程序来使用 camel 路由从 sftp 下载文件。这是我的代码

from("sftp://username@host/folder")
   .convertBodyTo(File.class)
   .process("processor")
   .routeId(routeId);

我想在从给定的 sftp 文件夹下载所有文件后关闭此路由。有人可以帮我解决这个问题吗?

FTP Component implements Polling Consumer, so you can use sendEmptyMessageWhenIdle option. With this option set to true, the Consumer emits empty message, when folder is empty, which you can then use in Content Based Router EIP.

要停止路由,您可以使用简单的处理器,ControlBus EIP, or any other approach described in FAQ - How can I stop a route from a route?

from("sftp://username@host/folder?sendEmptyMessageWhenIdle=true")
    .routeId(routeId)
    .choice()
        .when(body().isNull())
            .toF("controlbus:route?routeId=%s&action=stop&async=true", routeId)
        .otherwise()
            .convertBodyTo(File.class)
            .process("processor");