Red Hat Training

A Red Hat training course is available for Red Hat Fuse

8.9. Delayer


A delayer is a processor that enables you to apply a relative time delay to incoming messages.

Java DSL example

You can use the delay() command to add a relative time delay, in units of milliseconds, to incoming messages. For example, the following route delays all incoming messages by 2 seconds:
Alternatively, you can specify the time delay using an expression:
The DSL commands that follow delay() are interpreted as sub-clauses of delay(). Hence, in some contexts it is necessary to terminate the sub-clauses of delay() by inserting the end() command. For example, when delay() appears inside an onException() clause, you would terminate it as follows:
            .log("Halting for some time")

XML configuration example

The following example demonstrates the delay in XML DSL:
<camelContext xmlns="">
        <from uri="seda:a"/>
        <to uri="mock:result"/>
        <from uri="seda:b"/>
        <to uri="mock:result"/>

Creating a custom delay

You can use an expression combined with a bean to determine the delay as follows:
  delay().expression().method("someBean", "computeDelay").
Where the bean class could be defined as follows:
public class SomeBean {
  public long computeDelay() { 
     long delay = 0;
     // use java code to compute a delay value in millis
     return delay;

Asynchronous delaying

You can let the delayer use non-blocking asynchronous delaying, which means that Apache Camel schedules a task to be executed in the future. The task is responsible for processing the latter part of the route (after the delayer). This allows the caller thread to unblock and service further incoming messages. For example:
The same route can be written in the XML DSL, as follows:
   <from uri="activemq:queue:foo"/>
   <delay asyncDelayed="true">
   <to uri="activemq:aDealyedQueue"/>


The delayer pattern supports the following options:
Name Default Value Description
asyncDelayed false Camel 2.4: If enabled then delayed messages happens asynchronously using a scheduled thread pool.
executorServiceRef Camel 2.4: Refers to a custom Thread Pool to be used if asyncDelay has been enabled.
callerRunsWhenRejected true Camel 2.4: Is used if asyncDelayed was enabled. This controls if the caller thread should execute the task if the thread pool rejected the task.