Available as of Camel 2.1
A route policy
org.apache.camel.spi.RoutePolicy is used to control route(s) at runtime. For example you can use it to determine whether a route should be running or not. However the policies can support any kind of use cases.
How it works
You associate a route with a given
RoutePolicy and then during runtime Camel will invoke callbacks on this policy where you can implement your custom logic.
Camel provides a support class that is a good base class to extend
There are these callbacks invoked
onInit Camel 2.3
onRemove Camel 2.9
onStart Camel 2.9
onStop Camel 2.9
onSuspend Camel 2.9
onResume Camel 2.9
See the javadoc of the
org.apache.camel.spi.RoutePolicy for more details.
And also the implementation of the
org.apache.camel.impl.ThrottlingInflightRoutePolicy for a concrete example.
Camel provides the following policies out of the box:
org.apache.camel.impl.ThrottlingInflightRoutePolicy - a throttling based policy that automatic suspends/resumes route(s) based on metrics from the current in flight exchanges. You can use this to dynamic throttle e.g. a JMS consumer to avoid it consuming too fast.
As of Camel 2.5, Camel also provides an ability to schedule routes to be activated, de-activated, suspended and/or resumed at certain times during the day using a ScheduledRoutePolicy (offered via the camel-quartz component).
The ThrottlingInflightRoutePolicy is triggered when an Exchange is complete, which means that it requires at least one Exchange to be complete before it works.
The throttling inflight route policy has the following options:
A scope for either
Context which defines if the current number of inflight exchanges is context based or for that particular route.
The maximum threshold when the throttling will start to suspend the route if the current number of inlfight exchanges is higher than this value.
A percentage 0..100 which defines when the throttling should resume again in case it has been suspended.
The logging level used for logging the throttling activity.
The logger category.
ScheduledRoutePolicy (Simple and Cron based) using camel Quartz
For more details check out the following links
You configure the route policy as follows from Java DSL, using the
In Spring XML its a bit different as follows using the
Configuring policy sets
Available as of Camel 2.7
RoutePolicy has been further improved to allow addition of policy sets or a collection of policies that are concurrently applied on a route. The addition of policies is done as follows.
In the example below, the route testRoute has a startPolicy and throttlePolicy applied concurrently. Both policies are applied as necessary on the route.