How can I shutdown a standalone Apache Camel application in an automated way?

前端 未结 3 894
情话喂你
情话喂你 2021-01-03 01:59

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

3条回答
  •  甜味超标
    2021-01-03 02:48

    Completing Claus answer, this code run in a only once fashioned way Main:

    import org.apache.camel.builder.RouteBuilder;
    import org.apache.camel.main.Main;
    
    public class MyMainRouter extends RouteBuilder {
    
      static Main main;
    
      @Override
      public void configure() throws Exception {
        from("timer:foo?delay=5s")
            .log("Hello camel, main world after 5 seconds!")
            .process(processor -> main.completed());
      }
    
      public static void main(String[] args) throws Exception {
        main = new Main();
        main.addRouteBuilder(new MyMainRouter());
        main.run();
      }
    
    }
    

    After 5 seconds, the code will run only once, because we will call a processor that will call completed() method, wich internally have CountDownLatch stopping a route pattern from another thread.

提交回复
热议问题