从sftp文件夹下载所有文件后,关闭sftp骆驼路由

时间:2019-09-30 18:02:32

标签: spring-boot apache-camel camel-ftp

我正在开发一个spring-boot应用程序,以使用骆驼路线从sftp下载文件。这是我的代码

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

从给定的sftp文件夹下载所有文件后,我想关闭此路由。有人可以帮我吗?

1 个答案:

答案 0 :(得分:0)

FTP Component实现了Polling Consumer,因此您可以使用sendEmptyMessageWhenIdle选项。将此选项设置为true时,当文件夹为空时,使用者将发出空消息,然后您可以在Content Based Router EIP中使用它。

要停止路线,您可以使用简单的处理器ControlBus EIPFAQ - 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");
相关问题