I\'m trying to use Apache Camel to download and route files from an FTP server. However, files are only added to the FTP server once in a long while so having the program r
Adding this example that may be useful to others without digging all the examples in the link.
Define a bean/processor that will launch a separate thread. This new thread will call stop()
on the active CamelContext
.
public class ShutdownBean {
private final static Logger log = LoggerFactory.getLogger(ShutdownBean.class);
public void process(Exchange exchange) throws Exception {
final CamelContext camelContext = exchange.getContext();
Thread shutdownThread = new Thread(() -> {
Thread.currentThread().setName("ShutdownThread");
try {
camelContext.stop();
} catch (Exception e) {
log.error("Errore during shutdown", e);
}
});
shutdownThread.start();
}
}
In your application context define this route and call it when you need to shutdown Camel.
Note: enableHangupSupport()
is deprecated on newer Camel versions: is enabled by default now, so no longer need to call this method.