Quartz
Since Camel 2.12
Only consumer is supported
The Quartz component provides a scheduled delivery of messages using the Quartz Scheduler 2.x.
Maven users will need to add the following dependency to their pom.xml for this component:
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-quartz</artifactId>
<version>x.x.x</version>
<!-- use the same version as your Camel core version -->
</dependency> URI format
quartz://timerName?options quartz://groupName/timerName?options quartz://groupName/timerName?cron=expression quartz://timerName?cron=expression
The component uses either a CronTrigger or a SimpleTrigger. If no cron expression is provided, the component uses a simple trigger. If no groupName is provided, the quartz component uses the group name Camel_ followed by the management name of the CamelContext.
Configuring Options
Camel components are configured on two separate levels:
-
component level
-
endpoint level
Configuring Component Options
At the component level, you set general and shared configurations that are, then, inherited by the endpoints. It is the highest configuration level.
For example, a component may have security settings, credentials for authentication, urls for network connection and so forth.
Some components only have a few options, and others may have many. Because components typically have pre-configured defaults that are commonly used, then you may often only need to configure a few options on a component; or none at all.
You can configure components using:
-
the Component DSL.
-
in a configuration file (
application.properties,*.yamlfiles, etc). -
directly in the Java code.
Configuring Endpoint Options
You usually spend more time setting up endpoints because they have many options. These options help you customize what you want the endpoint to do. The options are also categorized into whether the endpoint is used as a consumer (from), as a producer (to), or both.
Configuring endpoints is most often done directly in the endpoint URI as path and query parameters. You can also use the Endpoint DSL and DataFormat DSL as a type safe way of configuring endpoints and data formats in Java.
A good practice when configuring options is to use Property Placeholders.
Property placeholders provide a few benefits:
-
They help prevent using hardcoded urls, port numbers, sensitive information, and other settings.
-
They allow externalizing the configuration from the code.
-
They help the code to become more flexible and reusable.
The following two sections list all the options, firstly for the component followed by the endpoint.
Component Options
The Quartz component supports the following options which are listed below.
| Name | Description | Default | Type |
|---|---|---|---|
Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions (if possible) occurred while the Camel consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. Important: This is only possible if the 3rd party component allows Camel to be alerted if an exception was thrown. Some components handle this internally only, and therefore bridgeErrorHandler is not possible. In other situations we may improve the Camel component to hook into the 3rd party component and make this possible for future releases. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored. | false | boolean | |
Whether to register the Quartz scheduler in JMX, so it can be managed from JMX: the component sets the Quartz property org.quartz.scheduler.jmx.export to true, unless the scheduler properties set it already. Only used for the scheduler that the component creates from the scheduler properties. | true | boolean | |
Whether to add the management name of the CamelContext to the instance name of the Quartz scheduler (the Quartz property org.quartz.scheduler.instanceName), such as DefaultQuartzScheduler-camel-1, so each CamelContext has a scheduler of its own. Quartz returns the scheduler it already has in the JVM for an instance name, so with false, the CamelContexts that use the same scheduler properties share one scheduler. Only used for the scheduler that the component creates from the scheduler properties. | true | boolean | |
Whether to prefix the trigger name, which is also the name of the job, with the id of the endpoint and an underscore, such as endpoint3_myTimer. The endpoint id is generated in the order the endpoints are created in the JVM, so it can differ after a restart. Can also be set on the endpoint. | false | boolean | |
The Quartz scheduler properties (the org.quartz. keys, such as org.quartz.threadPool.threadCount) for the scheduler that the component creates. They replace the default file org/quartz/quartz.properties of the Quartz JAR as a whole (they are not merged with it), so they must hold every setting that Quartz needs, such as the thread count of the thread pool. Takes precedence over propertiesRef and propertiesFile. | Map | ||
The file with the Quartz scheduler properties, used when neither properties nor propertiesRef is set. Loaded from the classpath by default; use the file: prefix for a file on the file system. It replaces the default file org/quartz/quartz.properties as a whole. Without any of these options, the component loads org/quartz/quartz.properties from the Quartz JAR, and not a quartz.properties at the root of the classpath or the file of the org.quartz.properties system property, as Quartz itself does. | String | ||
The name of a java.util.Properties or Map in the registry with the Quartz scheduler properties, used when the properties option is not set. It replaces the default file org/quartz/quartz.properties as a whole, like the properties option, and takes precedence over propertiesFile. | String | ||
Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc. | true | boolean | |
Autowired The Quartz scheduler to use, instead of the one that the component creates. When not set, the single Scheduler in the registry is used, such as the one of spring-boot-starter-quartz. The component does not configure this scheduler (the options properties, propertiesRef, propertiesFile, schedulerFactory, enableJmx, prefixInstanceName and interruptJobsOnShutdown are not used) and does not shut it down. It starts it once the routes have started, unless autoStartScheduler is false or the scheduler is already running. | Scheduler | ||
The Quartz SchedulerFactory that creates the scheduler, instead of a StdSchedulerFactory configured from the scheduler properties. The options properties, propertiesRef, propertiesFile, enableJmx and prefixInstanceName are then not used. | SchedulerFactory | ||
Whether the component starts the Quartz scheduler once the CamelContext has started (and when a route is added later), unless the scheduler is already running. With false, the scheduler stays in standby mode, and no trigger fires, until it is started in another way, such as with the Quartz API or JMX. | true | boolean | |
Whether to interrupt the running jobs when the component shuts down the scheduler that it created, instead of waiting for them to complete. The component sets the Quartz property org.quartz.scheduler.interruptJobsOnShutdown and shuts the scheduler down without waiting: an interrupted job stops the routing of its exchange and fails it with a RejectedExecutionException. Use with care, as it is often better to let the jobs complete and shut down gracefully, as the scheduler does by default. | false | boolean |
Endpoint Options
The Quartz endpoint is configured using URI syntax:
quartz:groupName/triggerName
With the following path and query parameters:
Path Parameters
| Name | Description | Default | Type |
|---|---|---|---|
The trigger group, which is also the group of the job. The group and the trigger name identify the trigger in the scheduler, and must be unique. Without a group in the URI, the group is Camel_ followed by the management name of the CamelContext. | Camel | String | |
Required The name of the trigger, which is also the name of the job. The group and the trigger name identify the trigger in the scheduler, and must be unique. | String |
Query Parameters
| Name | Description | Default | Type |
|---|---|---|---|
The cron expression of a cron trigger, such as 0 0/5 12-18 ? * MON-FRI, with the fields second, minute, hour, day of month, month, day of week and an optional year (the syntax of the Quartz CronExpression). In the endpoint URI, a + can be used instead of a space. Without a cron expression, the endpoint uses a simple trigger (see trigger.repeatInterval and trigger.repeatCount). | String | ||
Whether to remove the trigger from the scheduler (unschedule it) when the endpoint stops, such as when the route is removed or the CamelContext stops. Quartz then deletes the job too, unless it is durable (durableJob). With false, the trigger stays in the scheduler, paused, and the endpoint with the same group and trigger name resumes it when its route starts, also after a restart with a persistent job store. Cannot be true together with pauseJob. Not done with a clustered job store, or when the scheduler is already shut down. | true | boolean | |
Whether the job is durable: Quartz keeps it stored when no trigger points to it anymore, such as after the endpoint removed its trigger (deleteJob). A job that is not durable is deleted with its last trigger. | false | boolean | |
Whether to pause the trigger, and keep it in the scheduler, when the endpoint stops, such as when the route is removed or the CamelContext stops. Requires deleteJob=false: the route fails to start when both are true. The consumer already pauses the trigger when the route stops, so with deleteJob=false the trigger is also kept paused without this option. Not done with a clustered job store. | false | boolean | |
Whether the job requests recovery: when the scheduler stops abruptly (it crashes) while the job runs, Quartz runs the job again when the scheduler starts again, or on another node of a clustered scheduler (fail-over). This needs a persistent job store, such as the JDBC job store. | false | boolean | |
Whether to use a stateful job, which Quartz does not run concurrently (DisallowConcurrentExecution) and whose JobDataMap it stores again after each run (PersistJobDataAfterExecution): a fire waits until the previous run of the job has completed. By default, the job runs again in another thread of the scheduler when the trigger fires before the previous run has completed. | false | boolean | |
Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions (if possible) occurred while the Camel consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. Important: This is only possible if the 3rd party component allows Camel to be alerted if an exception was thrown. Some components handle this internally only, and therefore bridgeErrorHandler is not possible. In other situations we may improve the Camel component to hook into the 3rd party component and make this possible for future releases. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored. | false | boolean | |
To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this option is not in use. By default the consumer will deal with exceptions, that will be logged at WARN or ERROR level and ignored. | ExceptionHandler | ||
Sets the exchange pattern when the consumer creates an exchange. Enum values:
| ExchangePattern | ||
A Quartz Calendar that excludes times from the schedule of the trigger, such as holidays: the trigger does not fire at a time that the calendar excludes. The endpoint adds it to the scheduler under the name CamelQuartzCustomCalendar_ followed by the group, an underscore and the trigger name, and deletes it when it removes the trigger (deleteJob). | Calendar | ||
Whether to start the route even if the trigger will never fire, such as a cron trigger whose cron expression only matches past times, or whose end time (trigger.endAt) has passed: the endpoint does not schedule the trigger then, and logs a WARN. By default, Quartz refuses to schedule such a trigger, and the route fails to start. | false | boolean | |
Options of the Quartz job (the JobDetail), set as its bean properties, such as description. An option that the job does not have is ignored. This is a multi-value option with prefix: job. | Map | ||
Whether to prefix the trigger name, which is also the name of the job, with the id of the endpoint and an underscore, such as endpoint3_myTimer. The endpoint id is generated in the order the endpoints are created in the JVM, so it can differ after a restart. Setting this option on an endpoint sets the option of the component, so it also applies to the quartz endpoints created after this one. | false | boolean | |
Options of the Quartz trigger. A cron trigger supports timeZone (a java.util.TimeZone ID, such as Europe/Stockholm; an ID that Java does not know means GMT), startAt and endAt (a date in the format yyyy-MM-dd’T’HH:mm:ssz, such as 2026-11-30T14:00:00UTC). A simple trigger supports repeatCount (the number of times it repeats after the first fire: 0 fires once, -1, the default, repeats without limit) and repeatInterval (the time between two fires in milliseconds, 1000 by default, which must be greater than 0 when the trigger repeats). Any other option is set as a bean property of the trigger, such as misfireInstruction: the endpoint sets the misfire instruction to 1 (MISFIRE_INSTRUCTION_FIRE_NOW of a simple trigger, MISFIRE_INSTRUCTION_FIRE_ONCE_NOW of a cron trigger), instead of the smart policy (0) of Quartz. An option that the trigger does not have is ignored. When the scheduler starts after the start time of the trigger, the missed fire times fire one after the other. So with a short repeatInterval, the first fires can come faster than the interval. This is a multi-value option with prefix: trigger. | Map | ||
Whether the JobDataMap of the job holds the name of the CamelContext, instead of its management name (the default). The job uses this name to find the CamelContext when it fires, and the component registers the CamelContext in the scheduler context by its management name, so this works only when both names are the same. | false | boolean | |
Whether the component starts the Quartz scheduler once the CamelContext has started (and when a route is added later), unless the scheduler is already running. The scheduler is shared by the quartz endpoints: setting this option on an endpoint sets the option of the component, for all its endpoints. | true | boolean | |
The delay of the start time of the trigger (the earliest time it fires) after the endpoint schedules it, when the scheduler is already started, such as for a route added after the CamelContext has started: this lets the consumer start before the job fires. When the scheduler is not started yet, the start time is the current time, so a simple trigger fires first when the component starts the scheduler. A negative value moves the start time into the past, also when the scheduler is not started yet. With a cron trigger, trigger.startAt replaces this start time. | 500 | long |
Message Headers
The Quartz component supports the following message header(s), which is/are listed below:
| Name | Description | Default | Type |
|---|---|---|---|
| Constant: | The Quartz Calendar that excludes times from the schedule of the trigger, or null when the trigger has none. | Calendar | |
| Constant: | The time the trigger fired. | Date | |
| Constant: | The Quartz JobDetail of the job that runs, with its key and JobDataMap. | JobDetail | |
| Constant: | The instance of the Quartz job that runs, a CamelJob that sends the message to the route. | Job | |
| Constant: | The time the job ran, in milliseconds, as Quartz reports it. Quartz sets it only once the job has completed, so the route, which runs within the job, gets -1. | long | |
| Constant: | The JobDataMap of the job merged with the JobDataMap of the trigger, whose values win. | JobDataMap | |
| Constant: | The time the trigger fires next, or null when it does not fire again. | Date | |
| Constant: | The time the trigger fired before this fire, or null when this is its first fire. | Date | |
| Constant: | The number of times Quartz has run this fire of the job again after a failure that asked for a refire, 0 for the first run. | int | |
| Constant: | The result of the job, as Quartz holds it in the JobExecutionContext. The Camel job sets no result, so it is null. | Object | |
| Constant: | The time the trigger was scheduled to fire. It is earlier than fireTime when the fire was delayed, such as by a misfire. | Date | |
| Constant: | The Quartz Scheduler that runs the job. | Scheduler | |
| Constant: | The Quartz Trigger that fired. | Trigger | |
| Constant: | The name of the trigger that fired: the triggerName of the endpoint URI, prefixed with the endpoint id when prefixJobNameWithEndpointId is enabled. | String | |
| Constant: | The group of the trigger that fired: the groupName of the endpoint URI, or Camel (Camel_ and the name of the CamelContext, when it has one) when the URI has no group. | String | |
CamelMessageTimestamp (consumer) Constant: | The time the trigger fired, in milliseconds since the epoch. | long |
Message Body
The message body at each side of the Quartz component: Consumer is the body of the messages the consumer creates, Consumer reply the bodies a consumer that answers its caller can reply with, Producer input the bodies the producer can send or write, and Producer output the body after the producer.
| Side | Body | Description |
|---|---|---|
Consumer |
| No body: the message only starts the route. |
The bodies are the ones with the default options. A side that is not listed is not known, and tooling does not guess it. The carriers, the sides and the tools that use them are described in Message Body Types.
Usage
Each endpoint represents a different timer (in Quartz terms, a Trigger and `JobDetail).
Configuring quartz.properties file
By default, the Camel Quartz component loads the quartz.properties file from the org/quartz directory of the classpath, which is the default file in the Quartz JAR. Unlike Quartz itself, it does not read a quartz.properties file at the root of the classpath, or the file set by the org.quartz.properties system property. It logs a WARN when this system property is set, or else when it finds a quartz.properties file at the root of the classpath. To use such a file, set the propertiesFile option, for example to classpath:quartz.properties or file:/etc/myapp/quartz.properties. To keep the default file without the WARN, for example when the application keeps a quartz.properties file at the root of the classpath for a Quartz scheduler of its own, set propertiesFile to classpath:org/quartz/quartz.properties.
However, the Camel Quartz component also allows you to configure properties:
| Parameter | Default | Type | Description |
|---|---|---|---|
|
|
| You can configure a |
|
|
| File name of the properties to load from the classpath |
To do this, you can configure this in Spring XML as follows
<bean id="quartz" class="org.apache.camel.component.quartz.QuartzComponent">
<property name="propertiesFile" value="com/mycompany/myquartz.properties"/>
</bean> Using your own scheduler (spring-boot-starter-quartz)
The component uses the Quartz Scheduler set with its scheduler option, or else the single Scheduler of the registry, such as the scheduler of spring-boot-starter-quartz. It does not create a scheduler of its own then, so the options properties, propertiesRef and propertiesFile are not used, and it logs a WARN when one of them is set. The options schedulerFactory, enableJmx, prefixInstanceName and interruptJobsOnShutdown are not used either. Configure that scheduler instead, for example with the spring.quartz.properties.* properties of Spring Boot.
The component starts this scheduler once the routes have started, unless autoStartScheduler is false or the scheduler is already running. The routes add their jobs when they start, so a scheduler that is already running can fire a trigger before its route has started, and this fire is lost. The component logs a WARN when the scheduler is already running when it starts. Spring Boot starts the scheduler of spring-boot-starter-quartz before Camel, so let Camel start it:
spring.quartz.auto-startup=false The Quartz jobs of the application that are not Camel routes then also start when Camel starts the scheduler.
Enabling Quartz scheduler in JMX
You need to configure the quartz scheduler properties to enable JMX. That is typically setting the option "org.quartz.scheduler.jmx.export" to a true value in the configuration file.
This option is set to true by default, unless explicitly disabled.
Clustering
If you use Quartz in clustered mode, e.g., the JobStore is clustered. Then the Quartz component will not pause/remove triggers when a node is being stopped/shutdown. This allows the trigger to keep running on the other nodes in the cluster.
| When running in clustered node, no checking is done to ensure unique job name/group for endpoints. |
Keeping the trigger when the route stops
With deleteJob=false (also with pauseJob=true), the route keeps its trigger in the scheduler when it stops, and pauses it. It marks the trigger as paused by Camel, with the key CamelQuartzTriggerPausedByCamel in the JobDataMap of its job, so that a route with this trigger resumes it when it starts: the same route started again, a route that was removed and added again, or the route after a restart of the application with a persistent job store.
A trigger that was paused outside Camel (with the Quartz API or JMX, for example while the route runs) has no such mark, and stays paused when the route starts, also when the same route is stopped and started again. A pre-configured trigger that you reuse with the Camel URI is resumed only if Camel paused it. To keep a trigger that Camel paused from firing, keep the route stopped.
Message Headers
Camel adds the getters from the Quartz Execution Context as header values. The following headers are added:
calendar, fireTime, jobDetail, jobInstance, jobRunTime, mergedJobDataMap, nextFireTime, previousFireTime, refireCount, result, scheduledFireTime, scheduler, trigger, triggerName, triggerGroup.
The fireTime header contains the java.util.Date of when the exchange was fired.
Using Cron Triggers
Quartz supports Cron-like expressions for specifying timers in a handy format. You can use these expressions in the cron URI parameter; though, to preserve valid URI encoding, we allow + to be used instead of spaces.
For example, the following will fire a message every five minutes starting at 12pm (noon) to 6pm on weekdays:
-
Java
-
XML
-
YAML
from("quartz://myGroup/myTimerName?cron=0+0/5+12-18+?+*+MON-FRI")
.to("activemq:Totally.Rocks"); <route>
<from uri="quartz://myGroup/myTimerName?cron=0+0/5+12-18+?+*+MON-FRI"/>
<to uri="activemq:Totally.Rocks"/>
</route> - route:
from:
uri: quartz://myGroup/myTimerName
parameters:
cron: "0 0/5 12-18 ? * MON-FRI"
steps:
- to:
uri: activemq:Totally.Rocks which is equivalent to using the cron expression
0 0/5 12-18 ? * MON-FRI
The following table shows the URI character encodings we use to preserve valid URI syntax:
| URI Character | Cron character |
|---|---|
| Space |
Specifying time zone
The Quartz Scheduler allows you to configure time zone per trigger. For example, to use a time zone of your country, then you can do as follows:
quartz://groupName/timerName?cron=0+0/5+12-18+?+*+MON-FRI&trigger.timeZone=Europe/Stockholm
The timeZone value is the values accepted by java.util.TimeZone.
Specifying start date
The Quartz Scheduler allows you to configure start date per trigger. You can provide the start date in the date format yyyy-MM-dd’T’HH:mm:ssz.
quartz://groupName/timerName?cron=0+0/5+12-18+?+*+MON-FRI&trigger.startAt=2023-11-22T14:32:36UTC
Specifying end date
The Quartz Scheduler allows you to configure end date per trigger. You can provide the end date in the date format yyyy-MM-dd’T’HH:mm:ssz.
quartz://groupName/timerName?cron=0+0/5+12-18+?+*+MON-FRI&trigger.endAt=2023-11-22T14:32:36UTC
Note: Start and end dates may be affected by time drifts and unpredictable behavior during daylight-saving time changes. Exercise caution, especially in environments where precise timing is critical.
Configuring misfire instructions
The quartz scheduler can be configured with a misfire instruction to handle misfire situations for the trigger. The concrete trigger type that you are using will have defined a set of additional MISFIRE_INSTRUCTION_XXX constants that may be set as this property’s value.
For example, to configure the simple trigger to use misfire instruction 4:
quartz://myGroup/myTimerName?trigger.repeatInterval=2000&trigger.misfireInstruction=4
And likewise, you can configure the cron trigger with one of its misfire instructions as well:
quartz://myGroup/myTimerName?cron=0/2+*+*+*+*+?&trigger.misfireInstruction=2
The simple and cron triggers have the following misfire instructions representative:
SimpleTrigger.MISFIRE_INSTRUCTION_FIRE_NOW = 1 (default)
Instructs the Scheduler that upon a mis-fire situation, the SimpleTrigger wants to be fired now by Scheduler.
This instruction should typically only be used for 'one-shot' (non-repeating) Triggers. If it is used on a trigger with a repeat count greater than 0, then it is equivalent to the instruction MISFIRE_INSTRUCTION_RESCHEDULE_NOW_WITH_REMAINING_REPEAT_COUNT.
SimpleTrigger.MISFIRE_INSTRUCTION_RESCHEDULE_NOW_WITH_EXISTING_REPEAT_COUNT = 2
Instructs the Scheduler that upon a mis-fire situation, the SimpleTrigger wants to be re-scheduled to now (even if the associated Calendar excludes now) with the repeat count left as-is. This does obey the Trigger end-time, however, so if now is after the end-time the Trigger will not fire again.
Use of this instruction causes the trigger to 'forget' the start-time and repeat-count that it was originally setup with. This is only an issue if you for some reason wanted to be able to tell what the original values were at some later time.
SimpleTrigger.MISFIRE_INSTRUCTION_RESCHEDULE_NOW_WITH_REMAINING_REPEAT_COUNT = 3
Instructs the Scheduler that upon a mis-fire situation, the SimpleTrigger wants to be re-scheduled to now (even if the associated Calendar excludes now) with the repeat count set to what it would be, if it had not missed any firings. This does obey the Trigger end-time, however, so if now is after the end-time the Trigger will not fire again.
Use of this instruction causes the trigger to 'forget' the start-time and repeat-count that it was originally setup with. Instead, the repeat count on the trigger will be changed to whatever the remaining repeat count is. This is only an issue if you for some reason wanted to be able to tell what the original values were at some later time.
This instruction could cause the Trigger to go to the 'COMPLETE' state after firing now, if all the repeat-fire-times where missed.
SimpleTrigger.MISFIRE_INSTRUCTION_RESCHEDULE_NEXT_WITH_REMAINING_COUNT = 4
Instructs the Scheduler that upon a mis-fire situation, the SimpleTrigger wants to be re-scheduled to the next scheduled time after now - taking into account any associated Calendar and with the repeat count set to what it would be, if it had not missed any firings.
| This instruction could cause the Trigger to go directly to the 'COMPLETE' state if all fire-times where missed. |
SimpleTrigger.MISFIRE_INSTRUCTION_RESCHEDULE_NEXT_WITH_EXISTING_COUNT = 5
Instructs the Scheduler that upon a mis-fire situation, the SimpleTrigger wants to be re-scheduled to the next scheduled time after now - taking into account any associated Calendar, and with the repeat count left unchanged.
| This instruction could cause the Trigger to go directly to the 'COMPLETE' state if the end-time of the trigger has arrived. |
CronTrigger.MISFIRE_INSTRUCTION_FIRE_ONCE_NOW = 1 (default)
Instructs the Scheduler that upon a mis-fire situation, the CronTrigger wants to be fired now by Scheduler.
CronTrigger.MISFIRE_INSTRUCTION_DO_NOTHING = 2
Instructs the Scheduler that upon a mis-fire situation, the CronTrigger wants to have its next-fire-time updated to the next time in the schedule after the current time (taking into account any associated Calendar. However, it does not want to be fired now.
Using QuartzScheduledPollConsumerScheduler
The Quartz component provides a Polling Consumer scheduler which allows using cron based scheduling for Polling Consumers such as the File and FTP consumers.
For example, to use a cron based expression to poll for files every second, then a Camel route can be defined simply as:
-
Java
-
XML
-
YAML
from("file:inbox?scheduler=quartz&scheduler.cron=0/2+*+*+*+*+?")
.to("bean:process"); <route>
<from uri="file:inbox?scheduler=quartz&scheduler.cron=0/2+*+*+*+*+?"/>
<to uri="bean:process"/>
</route> - route:
from:
uri: file:inbox
parameters:
scheduler: quartz
scheduler.cron: "0/2 * * * * ?"
steps:
- to:
uri: bean:process Notice we define the scheduler=quartz to instruct Camel to use the Quartz-based scheduler. Then we use scheduler.xxx options to configure the scheduler. The Quartz scheduler requires the cron option to be set.
The following options are supported:
| Parameter | Default | Type | Description |
|---|---|---|---|
|
|
| To use a custom Quartz scheduler. If none is configured, then the shared scheduler from the Quartz component is used. |
|
|
| Mandatory: To define the cron expression for triggering the polls. |
|
|
| To specify the trigger id. If none is provided, then a UUID is generated and used. |
|
|
| To specify the trigger group. |
|
|
| The time zone to use for the CRON trigger. |
Remember that configuring these options from the endpoint URIs must be prefixed with scheduler.. For example, to configure the trigger id and group: |
-
Java
-
XML
-
YAML
from("file:inbox?scheduler=quartz&scheduler.cron=0/2+*+*+*+*+?&scheduler.triggerId=myId&scheduler.triggerGroup=myGroup")
.to("bean:process"); <route>
<from uri="file:inbox?scheduler=quartz&scheduler.cron=0/2+*+*+*+*+?&scheduler.triggerId=myId&scheduler.triggerGroup=myGroup"/>
<to uri="bean:process"/>
</route> - route:
from:
uri: file:inbox
parameters:
scheduler: quartz
scheduler.cron: "0/2 * * * * ?"
scheduler.triggerId: myId
scheduler.triggerGroup: myGroup
steps:
- to:
uri: bean:process There is also a CRON scheduler in Spring, so you can use the following as well:
-
Java
-
XML
-
YAML
from("file:inbox?scheduler=spring&scheduler.cron=0/2+*+*+*+*+?")
.to("bean:process"); <route>
<from uri="file:inbox?scheduler=spring&scheduler.cron=0/2+*+*+*+*+?"/>
<to uri="bean:process"/>
</route> - route:
from:
uri: file:inbox
parameters:
scheduler: spring
scheduler.cron: "0/2 * * * * ?"
steps:
- to:
uri: bean:process Example
Users can then use the cron component instead of the quartz component, as in the following route:
-
Java
-
XML
-
YAML
from("cron://name?schedule=0+0/5+12-18+?+*+MON-FRI")
.to("activemq:Totally.Rocks"); <route>
<from uri="cron://name?schedule=0+0/5+12-18+?+*+MON-FRI"/>
<to uri="activemq:Totally.Rocks"/>
</route> - route:
from:
uri: cron://name
parameters:
schedule: "0 0/5 12-18 ? * MON-FRI"
steps:
- to:
uri: activemq:Totally.Rocks