完成后骆驼停止上下文

如果我的理解是正确的,那么骆驼路线没有“完整”状态,因此说类似的话是没有意义的


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();


阿晨1998
浏览 205回答 2
2回答

肥皂起泡泡

正如在前面的答案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 requiredprivate 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
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java