简体   繁体   English

骆驼运行时计时器更改

[英]Camel runtime timer change

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. 我正在使用osgi蓝图来配置适当的期限。 So how can I change timer(with name which I know) for example from route? 那么如何从路由更改计时器(具有我知道的名称)呢?

You can add a bean to your route that implements org.apache.camel.CamelContextAware. 您可以在实现org.apache.camel.CamelContextAware的路由中添加一个bean。 Camel will inject a reference to the context on start-up. Camel将在启动时注入对上下文的引用。 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. 我不知道这是否足以让触发器根据您的新周期/ cron表达式重新安排。 Maybe you have to cast the endpoint to TimerEndpoint and work with it directly, eg setting a new Timer instance based on your new schedule. 也许您必须将端点转换为TimerEndpoint并直接使用它,例如,根据新的时间表设置新的Timer实例。

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. 尽管Ralf提到的内容会有所帮助,因为这使您可以从Bean访问CamelContext,在其中您可以控制路线的生命周期。

But see also the control bus EIP about such things 但也请参见控制总线EIP的相关说明

If you use quartz instead of timer then it has a JMX API that allows to update its schedulers/triggers at runtime. 如果使用石英而不是计时器,则它具有JMX API,该API允许在运行时更新其调度程序/触发器。 We do this in hawtio so you can have a visual UI to do updates 我们在hawtio中执行此操作,因此您可以使用可视UI进行更新

You can do that as well from Java code using quartz JMX API. 您也可以使用石英JMX API从Java代码执行此操作。

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. 我在Apache Camel JIRA跟踪器中记录了一张票,目的是将来改进Camel以使其更容易更新计时器使用者: https : //issues.apache.org/jira/browse/CAMEL-7153-然后您可以实施起来更容易。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM