为了账号安全,请及时绑定邮箱和手机立即绑定

完成后骆驼停止上下文

完成后骆驼停止上下文

阿晨1998 2021-05-31 16:59:46
如果我的理解是正确的,那么骆驼路线没有“完整”状态,因此说类似的话是没有意义的camelContext.addRoute(route1);camelContext.start();while(0) {    ifComplete(route1)        break;}camelContext.stop();在我见过的大多数例子中,它是这样写的camelContext.start();Thread.sleep(someDeterminedAmountOfTime);camelContext.stop();我在大概的某个地方进行了数据转换,25Gb我不知道这需要多长时间。那么这里的最佳实践是什么?(我在想可能严重高估了完成时间,然后尝试使用我的路线中的日志消息从那里进行微调)路线:CsvDataFormat csv = new CsvDataFormat();from(file:/path/to/file/?fileName=fileName&noop=true).split(body().tokenize("/n")).streaming().unmarshall(csv).process(new CsvParserProcess()).marshal(csv).to(file:/path/to/new/file/?fileName=out.csv).log("finished").end();
查看完整描述

2 回答

?
肥皂起泡泡

TA贡献1829条经验 获得超6个赞

正如在前面的答案org.apache.camel.main.Main类中提到的那样,这就是您要寻找的。run()此类中的方法将启动另一个线程并将处于活动状态,除非您手动终止其执行。对于应该运行更长时间的独立集成,请查看 apache camel 网站long-running-camel-integrations 中的此参考


简而言之,你最终会做这样的事情。


public final class Application {


private static Logger logger = LoggerFactory.getLogger(Application.class);


public static void main(String[] args) {

    // This is the org.apache.camel.main.Main method

    final Main main = new Main();


    // Add lifecycle hooks to the main

    main.addMainListener(new Events());


    // Add routes to the camel context

    main.addRouteBuilder(new InvoiceGenerator());

    main.addRouteBuilder(new CustomerInvoicePayment());

    main.addRouteBuilder(new BankProcessPayment());

    main.addRouteBuilder(new CustomerNotificationProcessor());

    main.addRouteBuilder(new InvoiceNotificationProcessor());


    try {

        // Run the main method

        main.run();

    } catch (Exception e) {

        logger.error("Error starting Camel Application ", e);

        e.printStackTrace();

    }

}


// This class provides a few lifecycle hooks. Use them if required

private static class Events extends MainListenerSupport {

    private static Logger logger = LoggerFactory.getLogger(Events.class);


    @Override

    public void afterStart(final MainSupport main) {logger.info("Camel app is now started!");}


    @Override

    public void beforeStop(final MainSupport main) {logger.info("Camel app is shutting down!");}

}


}

您可以在这里查看工作示例 - apache-camel-kafka


查看完整回答
反对 回复 2021-06-02
  • 2 回答
  • 0 关注
  • 204 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信