我正在开发一个spring-boot应用程序,以使用骆驼路线从sftp下载文件。这是我的代码
from("sftp://username@host/folder")
.convertBodyTo(File.class)
.process("processor")
.routeId(routeId);
从给定的sftp文件夹下载所有文件后,我想关闭此路由。有人可以帮我吗?
答案 0 :(得分:0)
FTP Component实现了Polling Consumer,因此您可以使用sendEmptyMessageWhenIdle
选项。将此选项设置为true
时,当文件夹为空时,使用者将发出空消息,然后您可以在Content Based Router EIP中使用它。
要停止路线,您可以使用简单的处理器ControlBus EIP或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");