Apache的骆驼 - 在启动时触发一个任务只运行一次 [英] Apache Camel - Triggering a task on startup to run only once

查看:460
本文介绍了Apache的骆驼 - 在启动时触发一个任务只运行一次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作用骆驼和放大器的Java项目;弹簧。我们愿在一个singleton bean触发初始化方法后春做完的事情,骆驼已完成建设的所有路由。

I am working on a Java project using Camel & Spring. We would like to trigger an initialize method on a singleton bean after Spring finished doing its thing and Camel has finished building all routes.

我们不能拨打类的创建时间的方法,因为它具有动态联反应的其他类,它从@Component春天注释回升,我们不知道当/如果这些类已经被加载尚未实际运行的init方法构造函数的一部分。

We cant call the method at class creation time as it has dynamic linkings to other classes that it picks up from the @Component spring annotation and we dont know when/if these classes have been loaded yet to actually run the init method as part of a constructor.

我该如何去调用一个方法或方法来一次之后骆驼启动完成后运行?

How can I go about invoking a method or methods to run only once right after Camel startup is complete?

谢谢!

推荐答案

如果这个bean 必须 CamelContext后调用已经开始的所有路由等,则可以作为本建议使用具有路由计时器。

If the bean must be invoked after CamelContext has started all the routes etc, then you can as Ben suggest use a route with a timer.

一个可能更好的替代方法是使用从骆驼的事件通知API。然后调用在CamelContextStartedEvent逻辑被解雇。
在事件通知API在这里的一些细节:<一href=\"http://camel.apache.org/eventnotifier-to-log-details-about-all-sent-exchanges.html\">http://camel.apache.org/eventnotifier-to-log-details-about-all-sent-exchanges.html

A possible better alternative is to use the EventNotifier API from Camel. And then invoke the logic on the CamelContextStartedEvent being fired. Some details on the EventNotifier API here: http://camel.apache.org/eventnotifier-to-log-details-about-all-sent-exchanges.html

这篇关于Apache的骆驼 - 在启动时触发一个任务只运行一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆