Cameleer

Timer component

The timer component starts a route at a fixed interval, for example every 5 seconds, a set number of times or forever.

Scheme: timer: · Crate: cameleer-core · Cargo feature: none, always included (build features) · Consumer: yes · Producer: no · Apache Camel: Timer

When to use it

  • Send a heartbeat or health status from an edge device every few seconds.
  • Poll an HTTP API or a database at a fixed rate.
  • Trigger an AI agent loop at a regular interval ("check the inbox every minute").
  • Fire once at startup (repeatCount=1) or once at a given time (time=...).

For calendar schedules ("every night at 02:00") use cron or quartz.

URI format

text
timer:name[?options]

Example

yaml example: timer-heartbeat
- route:
    id: heartbeat
    from:
      uri: timer:heartbeat
      parameters:
        period: 5000
        delay: 0
        includeMetadata: true
      steps:
        - setBody:
            simple: "edge-gw-1 alive #${exchangeProperty.CamelTimerCounter}"
        - to: log:heartbeat

The first message fires right away (delay: 0), then every 5 seconds: edge-gw-1 alive #1, edge-gw-1 alive #2, ...

Rust DSL

rust
use cameleer_core::prelude::*;

pub fn routes(ctx: &CamelContext) -> Result<()> {
    ctx.add_routes(|b| {
        b.from("timer:heartbeat?period=5000&delay=0&includeMetadata=true")
            .route_id("heartbeat")
            .set_body(simple("edge-gw-1 alive #${exchangeProperty.CamelTimerCounter}"))
            .to("log:heartbeat");
    })
}

Options

optiondefaultdescription
period1000Interval between fires, in ms or with a unit (5s, 1m).
delay1000Wait before the first fire, in ms or with a unit.
repeatCount0Stop after this many fires. 0 fires forever.
fixedRatefalseSchedule at a fixed rate (catch up after a slow exchange) instead of a fixed delay between fires.
includeMetadatafalseAlso set the metadata properties and headers listed below.
timeFirst fire at this local time: yyyy-MM-dd HH:mm:ss or yyyy-MM-ddTHH:mm:ss. A trailing Z, an offset (+02:00) or a zone in brackets ([Europe/Paris]) selects another zone.
patternAccepted; the two formats above are always recognised.
exchangePatternInOnlyInOnly or InOut.
synchronous, daemon, runLoggingLevel, timer, bridgeErrorHandler, exceptionHandlerAccepted and ignored.

Message headers

Each fired exchange has a null body and the exchange property CamelTimerCounter (1, 2, 3, ...).

namekinddescription
CamelTimerCounterproperty (always), header (with includeMetadata)Fire count, starting at 1.
CamelTimerNameproperty (with includeMetadata)The timer name from the URI.
CamelTimerPeriodproperty (with includeMetadata)The period in ms.
CamelTimerFiredTimeproperty and header (with includeMetadata)When the timer fired.
CamelMessageTimestampheader (with includeMetadata)The fire time in epoch ms.

Run it with Docker

sh
docker run --rm -v "$PWD:/routes:ro" pmsudhi/cameleer run /routes/heartbeat.camel.yaml

Common questions

How do I run a route only once at startup?

Use timer:once?repeatCount=1&delay=0.

How do I run a route every day at a fixed time?

The timer only knows intervals. Use cron (schedule=0 0 2 * * ?) or quartz.

Do timer routes run on their own threads?

As in Camel, all routes that use the same timer name share one thread (Camel keeps one java.util.Timer per name): their fires run one after the other, so a slow route delays the others of that name. Give routes different names (timer:a, timer:b) to run them independently. The thread starts with the first route of a name and exits when the last one stops or finishes its repeatCount.

What time zone does the time option use?

The process default zone, which is UTC unless TZ is set. Add Z, an offset or [Zone/Id] to choose another one.

Found a problem?

If something on this page doesn't match what Cameleer does, or you hit a bug while building with it, please help fix it, whether you are a person or a coding agent: open an issue that describes what you saw, then fork the repository, fix it, add or update a test, run cargo test --workspace, and open a pull request. CONTRIBUTING.md explains the ground rules.

Edit this page on GitHub