Available as of Camel 2.1
A route policy
How it works
You associate a route with a given
There are these callbacks invoked:
See the Javadoc of the
Camel provides the following policies out of the box:
As of Camel 2.5, Camel also provides an ability to schedule routes to be activated, deactivated, suspended and/or resumed at certain times during the day using a ScheduledRoutePolicy (offered via the camel-quartz component).
If you want to dynamic suspend/resume routes as the
A scope for either
The maximum threshold when the throttling will start to suspend the route if the current number of inflight exchanges is higher than this value.
The logging level used for logging the throttling activity.
The logger category.
ThrottlingInflightRoutePolicy compared to the [Throttler] EIP
ThrottlingInflightRoutePolicy compared to Throttler is that it does not block during throttling. It does throttling that is approximate based, meaning that its more coarse grained and not explicit precise as the Throttler. The Throttler can be much more accurate and only allow a specific number of messages being passed per a given time unit. Also the
ThrottlingInflightRoutePolicy is based its metrics on number of inflight exchanges where as Throttler is based on number of messages per time unit.
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
throttlePolicy applied concurrently. Both policies are applied as necessary on the route.
Available as of Camel 2.14
If you want to use a route policy for every route, you can use a
org.apache.camel.spi.RoutePolicyFactory as a factory for creating a
RoutePolicy instance for each route. This can be used when you want to use the same kind of route policy for every routes. Then you need to only configure the factory once, and every route created will have the policy assigned.
There is API on CamelContext to add a factory, as shown below
And from XML DSL you just define a
<bean> with the factory
The factory has a single method that creates the route policy
Note you can have as many route policy factories as you want. Just call the
addRoutePolicyFactory again, or declare the other factories as
<bean> in XML.
- Route Throttling Example for an example using this in practice with the
- ScheduledRoutePolicy for information on policy based scheduling capability for camel routes
- MetricsRoutePolicyFactory for information on a policy using the metrics component to expose route statistics using the metrics library.