Fuse 6 is no longer supported
As of February 2025, Red Hat Fuse 6 is no longer supported. If you are using Fuse 6, please upgrade to Red Hat build of Apache Camel.Ce contenu n'est pas disponible dans la langue sélectionnée.
2.10. Scheduled Route Policy
2.10.1. Overview of Scheduled Route Policies Copier lienLien copié sur presse-papiers!
Overview Copier lienLien copié sur presse-papiers!
Scheduling tasks Copier lienLien copié sur presse-papiers!
- Start a route—start the route at the time (or times) specified. This event only has an effect, if the route is currently in a stopped state, awaiting activation.
- Stop a route—stop the route at the time (or times) specified. This event only has an effect, if the route is currently active.
- Suspend a route—temporarily de-activate the consumer endpoint at the start of the route (as specified in
from()
). The rest of the route is still active, but clients will not be able to send new messages into the route. - Resume a route—re-activate the consumer endpoint at the start of the route, returning the route to a fully active state.
Quartz component Copier lienLien copié sur presse-papiers!
2.10.2. Simple Scheduled Route Policy Copier lienLien copié sur presse-papiers!
Overview Copier lienLien copié sur presse-papiers!
org.apache.camel.routepolicy.quartz.SimpleScheduledRoutePolicy
org.apache.camel.routepolicy.quartz.SimpleScheduledRoutePolicy
Dependency Copier lienLien copié sur presse-papiers!
camel-quartz
. For example, if you are using Maven as your build system, you would need to add a dependency on the camel-quartz
artifact.
Java DSL example Copier lienLien copié sur presse-papiers!
startTime
, is defined to be 3 seconds after the current time. The policy is also configured to start the route a second time, 3 seconds after the initial start time, which is configured by setting routeStartRepeatCount
to 1 and routeStartRepeatInterval
to 3000 milliseconds.
routePolicy()
DSL command in the route.
Example 2.7. Java DSL Example of Simple Scheduled Route
routePolicy()
with multiple arguments.
XML DSL example Copier lienLien copié sur presse-papiers!
routePolicyRef
attribute on the route
element.
Example 2.8. XML DSL Example of Simple Scheduled Route
routePolicyRef
as a comma-separated list of bean IDs.
Defining dates and times Copier lienLien copié sur presse-papiers!
java.util.Date
type.The most flexible way to define a Date
instance is through the java.util.GregorianCalendar class. Use the convenient constructors and methods of the GregorianCalendar
class to define a date and then obtain a Date
instance by calling GregorianCalendar.getTime()
.
GregorianCalendar
constructor as follows:
GregorianCalendar
class also supports the definition of times in different time zones. By default, it uses the local time zone on your computer.
Graceful shutdown Copier lienLien copié sur presse-papiers!
Logging Inflight Exchanges on Timeout Copier lienLien copié sur presse-papiers!
org.apache.camel.impl.DefaultShutdownStrategy
, then it logs the same inflight exchange information.
2015-01-12 13:23:23,656 [- ShutdownTask] INFO DefaultShutdownStrategy - There are 1 inflight exchanges: InflightExchange: [exchangeId=ID-davsclaus-air-62213-1421065401253-0-3, fromRouteId=route1, routeId=route1, nodeId=delay1, elapsed=2007, duration=2017]
2015-01-12 13:23:23,656 [- ShutdownTask] INFO DefaultShutdownStrategy - There are 1 inflight exchanges:
InflightExchange: [exchangeId=ID-davsclaus-air-62213-1421065401253-0-3, fromRouteId=route1, routeId=route1, nodeId=delay1, elapsed=2007, duration=2017]
context.getShutdownStrategegy().setLogInflightExchangesOnTimeout(false);
context.getShutdownStrategegy().setLogInflightExchangesOnTimeout(false);
Scheduling tasks Copier lienLien copié sur presse-papiers!
Starting a route Copier lienLien copié sur presse-papiers!
Parameter | Type | Default | Description |
---|---|---|---|
routeStartDate | java.util.Date | None | Specifies the date and time when the route is started for the first time. |
routeStartRepeatCount | int | 0 | When set to a non-zero value, specifies how many times the route should be started. |
routeStartRepeatInterval | long | 0 | Specifies the time interval between starts, in units of milliseconds. |
Stopping a route Copier lienLien copié sur presse-papiers!
Parameter | Type | Default | Description |
---|---|---|---|
routeStopDate | java.util.Date | None | Specifies the date and time when the route is stopped for the first time. |
routeStopRepeatCount | int | 0 | When set to a non-zero value, specifies how many times the route should be stopped. |
routeStopRepeatInterval | long | 0 | Specifies the time interval between stops, in units of milliseconds. |
routeStopGracePeriod | int | 10000 | Specifies how long to wait for the current exchange to finish processing (grace period) before forcibly stopping the route. Set to 0 for an infinite grace period. |
routeStopTimeUnit | long | TimeUnit.MILLISECONDS | Specifies the time unit of the grace period. |
Suspending a route Copier lienLien copié sur presse-papiers!
Parameter | Type | Default | Description |
---|---|---|---|
routeSuspendDate | java.util.Date | None | Specifies the date and time when the route is suspended for the first time. |
routeSuspendRepeatCount | int | 0 | When set to a non-zero value, specifies how many times the route should be suspended. |
routeSuspendRepeatInterval | long | 0 | Specifies the time interval between suspends, in units of milliseconds. |
Resuming a route Copier lienLien copié sur presse-papiers!
Parameter | Type | Default | Description |
---|---|---|---|
routeResumeDate | java.util.Date | None | Specifies the date and time when the route is resumed for the first time. |
routeResumeRepeatCount | int | 0 | When set to a non-zero value, specifies how many times the route should be resumed. |
routeResumeRepeatInterval | long | 0 | Specifies the time interval between resumes, in units of milliseconds. |
2.10.3. Cron Scheduled Route Policy Copier lienLien copié sur presse-papiers!
Overview Copier lienLien copié sur presse-papiers!
org.apache.camel.routepolicy.quartz.CronScheduledRoutePolicy
org.apache.camel.routepolicy.quartz.CronScheduledRoutePolicy
Dependency Copier lienLien copié sur presse-papiers!
camel-quartz
. For example, if you are using Maven as your build system, you would need to add a dependency on the camel-quartz
artifact.
Java DSL example Copier lienLien copié sur presse-papiers!
*/3 * * * * ?
, which triggers a start event every 3 seconds.
routePolicy()
DSL command in the route.
Example 2.9. Java DSL Example of a Cron Scheduled Route
routePolicy()
with multiple arguments.
XML DSL example Copier lienLien copié sur presse-papiers!
routePolicyRef
attribute on the route
element.
Example 2.10. XML DSL Example of a Cron Scheduled Route
routePolicyRef
as a comma-separated list of bean IDs.
Defining cron expressions Copier lienLien copié sur presse-papiers!
cron
utility, which schedules jobs to run in the background on a UNIX system. A cron expression is effectively a syntax for wildcarding dates and times that enables you to specify either a single event or multiple events that recur periodically.
Seconds Minutes Hours DayOfMonth Month DayOfWeek [Year]
Seconds Minutes Hours DayOfMonth Month DayOfWeek [Year]
Year
field is optional and usually omitted, unless you want to define an event that occurs once and once only. Each field consists of a mixture of literals and special characters. For example, the following cron expression specifies an event that fires once every day at midnight:
0 0 24 * * ?
0 0 24 * * ?
*
character is a wildcard that matches every value of a field. Hence, the preceding expression matches every day of every month. The ?
character is a dummy placeholder that means ignore this field. It always appears either in the DayOfMonth
field or in the DayOfWeek
field, because it is not logically consistent to specify both of these fields at the same time. For example, if you want to schedule an event that fires once a day, but only from Monday to Friday, use the following cron expression:
0 0 24 ? * MON-FRI
0 0 24 ? * MON-FRI
MON-FRI
. You can also use the forward slash character, /
, to specify increments. For example, to specify that an event fires every 5 minutes, use the following cron expression:
0 0/5 * * * ?
0 0/5 * * * ?
Scheduling tasks Copier lienLien copié sur presse-papiers!
Starting a route Copier lienLien copié sur presse-papiers!
Parameter | Type | Default | Description |
---|---|---|---|
routeStartString | String | None | Specifies a cron expression that triggers one or more route start events. |
Stopping a route Copier lienLien copié sur presse-papiers!
Parameter | Type | Default | Description |
---|---|---|---|
routeStopTime | String | None | Specifies a cron expression that triggers one or more route stop events. |
routeStopGracePeriod | int | 10000 | Specifies how long to wait for the current exchange to finish processing (grace period) before forcibly stopping the route. Set to 0 for an infinite grace period. |
routeStopTimeUnit | long | TimeUnit.MILLISECONDS | Specifies the time unit of the grace period. |
Suspending a route Copier lienLien copié sur presse-papiers!
Parameter | Type | Default | Description |
---|---|---|---|
routeSuspendTime | String | None | Specifies a cron expression that triggers one or more route suspend events. |
Resuming a route Copier lienLien copié sur presse-papiers!
Parameter | Type | Default | Description |
---|---|---|---|
routeResumeTime | String | None | Specifies a cron expression that triggers one or more route resume events. |
2.10.4. Route Policy Factory Copier lienLien copié sur presse-papiers!
Using Route Policy Factory Copier lienLien copié sur presse-papiers!
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 route. Then you need to only configure the factory once, and every route created will have the policy assigned.
context.addRoutePolicyFactory(new MyRoutePolicyFactory());
context.addRoutePolicyFactory(new MyRoutePolicyFactory());
<bean>
with the factory
<bean id="myRoutePolicyFactory" class="com.foo.MyRoutePolicyFactory"/>
<bean id="myRoutePolicyFactory" class="com.foo.MyRoutePolicyFactory"/>
addRoutePolicyFactory
again, or declare the other factories as <bean>
in XML.