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?
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.
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
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
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.
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.
© 2022 - 2024 — McMap. All rights reserved.