0
votes

I have a requirement to process the big file using these 2 case (1) Pull from file directory and push to FTP (2) Pull from one FTP and push to another FTP

I am creating a java maven dependency project which use camel components to process above use-case of file transfer, so I decided to use org.apache.camel.main.Main class to start my route, but the problem is my program is not getting closed even after file is processed successfully. Somewhere I read that using "System.exit()" would solve the problem but still problem exists.

My code-

Main camelMain = new Main();
camelMain.enableHangupSupport();
camelMain.addRouteBuilder(getRouteBuilderLocaltoFTP());
camelMain.run();

RouteBuilder

public void configure() throws Exception { 
    from(<File-Path>).routeId("local-to-ftp")
    .onCompletion().process(new Processor() {
                @Override
                public void process(Exchange exchange) throws Exception {
                    exchange.getContext().stop();       
                }
            })
            .toD(<FTP-Path>); 

Also tried using control-Bus .toF("controlbus:route?routeId=%s&action=stop&async=true", "local-to-ftp")

But in both the cases, routes are shutting down gracefully not closing the program.

Seek help in this.

2

2 Answers

1
votes

You can configure on the main to shutdown the application after X period of time, or after processing N number of messages. And you can set both of them AFAIR, eg shutdown after 2 minutes, and after 1 message processed.

Just check the methods on camelMain. Mind that this requires a recent version of Apache Camel.

0
votes

Various ways of Graceful Shutdown is documented here. You can try this code to shutdown a particular route

camelContext.getRouteController().stopRoute("routeId");
camelContext.removeRoute("routeId");