Since we're on a major migration process of this website, some component documents here are out of sync right now. In the meantime you may want to look at the early version of the new website
https://camel.apache.org/staging/
We would very much like to receive any feedback on the new site, please join the discussion on the Camel user mailing list.
How can I stop a route from a routeThe CamelContext provides API for managing routes at runtime. It has a Stopping a route during routing an existing message is a bit tricky. The reason for that is Camel will Graceful Shutdown the route you are stopping. And if you do that while a message is being routed the Graceful Shutdown will try to wait until that message has been processed. The best practice for stopping a route from a route, is to either
Using another thread to stop the route is also what is normally used when stopping Camel itself, or for example when an application in a server is stopped etc. Its too tricky and hard to stop a route using the same thread that currently is processing a message from the route. This is not advised to do, and can cause unforeseen side effects. Using a latch to stop Camel from a routeIn this example we use a Error formatting macro: snippet: java.lang.IndexOutOfBoundsException: Index: 20, Size: 20
And in the route we call the latch as shown: Error formatting macro: snippet: java.lang.IndexOutOfBoundsException: Index: 20, Size: 20
Using a thread to stop a route from a routeIn this example we use a separate Error formatting macro: snippet: java.lang.IndexOutOfBoundsException: Index: 20, Size: 20
And in the route we create the thread and call the Error formatting macro: snippet: java.lang.IndexOutOfBoundsException: Index: 20, Size: 20
Alternative solutionsCamel provides another feature for managing routes at runtime which is RoutePolicy. And CamelContext also provides API for suspend/resume of routes, and shutdown as well.
See more details about the Lifecycle. You can also use the ControlBus component to let it stop/start routes. See Also |