The simple scheduled route policy is a route policy that enables you to start, stop, suspend, and resume routes. The timing of these events is defined by providing the time and date of an initial event. Optionally, you can specify a certain number of subsequent repetitions.
The simple scheduled route policy depends on the Quartz component, which is part of
the camel-quartz module. You need to add a dependency on the
camel-quartz module to you Maven POM.
Simple scheduled route policies are an instance of the following class:
org.apache.camel.routepolicy.quartz.SimpleScheduledRoutePolicy
The SimpleScheduledRoutePolicy class has a number of
properties that are used to schedule when a route runs. They are all listed in
Simple Scheduled Route Policy.
You create a simple scheduled route policy by defining a Spring bean for the policy in your XML configuration file as shown in Example 11.1.
Example 11.1. Simple scheduled route policy
<bean id="date" class="org.apache.camel.routepolicy.quartz.SimpleDate"/> <bean id="startPolicy" class="org.apache.camel.routepolicy.quartz.SimpleScheduledRoutePolicy"> <property name="routeStartDate" ref="date"/> <property name="routeStartRepeatCount" value="1"/> <property name="routeStartRepeatInterval" value="3000"/> </bean>
As shown in Example 11.2, you add a policy to a
route by inserting a policy element immediately following
the from element. The policy
element wraps the portion of the route to which the policy applies.
Example 11.2. Simple scheduled route
<camelContext xmlns="http://camel.apache.org/schema/spring"> <route id="myroute"> <from uri="direct:start"/> <policy id="policy1" ref="startPolicy"> <filter id="filter1"> <language language="xpath">$type = in.body('foo')</language> <to uri="mock:success"/> </filter> </policy> </route> </camelContext>
When you configure a simple scheduled route policy to stop a route, the route stopping algorithm is automatically integrated with the graceful shutdown procedure (see Controlling Start-Up and Shutdown of Routes). This means that the task waits until the current exchange has finished processing before shutting down the route. You can set a timeout, however, that forces the route to stop after the specified time, irrespective of whether or not the route has finished processing the exchange.








