I am developing an spring-boot application to download files from sftp using camel route. Here is my code
from("sftp://username@host/folder")
.convertBodyTo(File.class)
.process("processor")
.routeId(routeId);
I want to shutdown this route after downloading all files from the given sftp folder. Can someone please help me on this?
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.
To stop route you can use simple processor, 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");