2 回答
![?](http://img1.sycdn.imooc.com/5458626a0001503602200220-100-100.jpg)
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
添加回答
举报