Camel runtime timer change

会有一股神秘感。 提交于 2019-12-13 00:35:20

问题


I have a question about camel and timers. I have several timers and one of them I want update in runtime. I'm using osgi blueprint to configure proper periods. So how can I change timer(with name which I know) for example from route?


回答1:


You can add a bean to your route that implements org.apache.camel.CamelContextAware. Camel will inject a reference to the context on start-up. Using the context you can get a reference of the timer/quartz endpoint and update its configuration.

What I don't know is whether this will be enough for the triggers to be re-scheduled according to your new periods/cron-expression. Maybe you have to cast the endpoint to TimerEndpoint and work with it directly, e.g. setting a new Timer instance based on your new schedule.




回答2:


The timer does not allow changing at runtime, you would need to stop the route, update the timer endpoint on the route, and start the route again.

Though what Ralf mention can help as this allows you to get access to the CamelContext from a bean where you can control the lifecycle of the route.

But see also the control bus EIP about such things

  • http://camel.apache.org/controlbus

If you use quartz instead of timer then it has a JMX API that allows to update its schedulers/triggers at runtime. We do this in hawtio so you can have a visual UI to do updates

  • http://hawt.io/plugins/quartz/

You can do that as well from Java code using quartz JMX API.

I logged a ticket in Apache Camel JIRA tracker with the idea of improving Camel in the future to make it easier to update the timer consumer: https://issues.apache.org/jira/browse/CAMEL-7153 - then you can do that easier when its implemented.



来源:https://stackoverflow.com/questions/21309081/camel-runtime-timer-change

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!