CronScheduledRoutePolicy
CronScheduledRoutePolicy is a ScheduledRoutePolicy that facilitates route activation, deactivation, suspension and resumption of routes based on a Quartz cron trigger.
| Relationship to the Quartz component All Scheduled route policies share the scheduler created by the Quartz component. In this way, scheduler, jobs and triggers can be managed in a common and consistent way. |
Using cron scheduled route policy
To use a CronScheduledRoutePolicy it is necessary to instantiate an object of the type org.apache.camel.routepolicy.quartz.CronScheduledRoutePolicy.
To perform a route operation at a given time, the following information must be provided.
Starting a route
| Parameter Name | Type | Default Value | Description |
|---|---|---|---|
routeStartTime | String | the initial scheduled date and time as a Cron Expression for route start |
Stopping a route
| Parameter Name | Type | Default Value | Description |
|---|---|---|---|
routeStopTime | String | the initial scheduled date and time as a Cron Expression for route stop | |
routeStopGracePeriod | int | 10000 | the time period to wait before initiating graceful route stop |
routeStopTimeUnit | long | TimeUnit.MILLISECONDS | the time unit for the grace period expressed as |
Configuring the route policy
Once the org.apache.camel.routepolicy.quartz.CronScheduledRoutePolicy is created it can be wired into the Camel route as follows:
In Java:
CronScheduledRoutePolicy startPolicy = new CronScheduledRoutePolicy();
startPolicy.setRouteStartTime("*/3 * * * * ?");
from("direct:start")
.routeId("testRoute").routePolicy(startPolicy).noAutoStartup()
.to("mock:success"); And with Spring XML:
<bean id="startPolicy" class="org.apache.camel.routepolicy.quartz.CronScheduledRoutePolicy">
<property name="routeStartTime" value="*/3 * * * * ?"/>
</bean>
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route id="testRoute" routePolicyRef="startPolicy" autoStartup="false">
<from uri="direct:start"/>
<to uri="mock:success"/>
</route>
</camelContext> | Notice how the route to be scheduled MUST be configured to not auto-startup, to let the route scheduler take control of starting and stopping the route accordingly. |