LibraryLink ToToggle FramesPrintFeedback

Delayer

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

You can use the delayer() 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:

from("seda:a").delayer(2000).to("mock:result");

Alternatively, you can specify the absolute time when a message should be dispatched. The absolute time value must be expressed in coordinated universal time (UTC), which is defined as the number of milliseconds that have elapsed since midnight, January 1, 1970. For example, to dispatch a message at the absolute time specified by the contents of the JMSTimestamp header, you can define a route like the following:

from("seda:a").delayer(header("JMSTimestamp")).to("mock:result");

You can also combine an absolute time with a relative time delay. For example, to delay an incoming message until the time specified in the JMSTimestamp header plus an additional 3 seconds, you define a route as follows:

from("seda:a").delayer(header("JMSTimestamp"), 3000).to("mock:result");

The preceding examples assume that delivery order is maintained. However, this could result in messages being delivered later than their specified time stamp. To avoid this, you can reorder the messages based on their delivery time, by combining the delayer pattern with the resequencer pattern. For example:

from("activemq:someQueue").
    resequencer(header("JMSTimestamp")).
    delayer(header("JMSTimestamp")).to("activemq:aDelayedQueue");

To delay an incoming message until the time specified in the JMSTimestamp header plus an additional 3 seconds, define a route using the following XML configuration:

<camelContext id="delayerRoute" xmlns="http://activemq.apache.org/camel/schema/spring">
  <route>
    <from uri="seda:a"/>
    <delayer>
      <simple>header.JMSTimestamp</simple>
      <delay>3000</delay>
    </delayer>
    <to uri="mock:result"/>
  </route>
</camelContext>

If you want to specify a relative time delay only, you must insert a dummy expression, <expression/>, in place of the absolute time expression. For example, to delay incoming messages by a relative time delay of 2 seconds, define a route as follows:

<camelContext id="delayerRoute2" xmlns="http://activemq.apache.org/camel/schema/spring">
  <route>
    <from uri="seda:a"/>
    <delayer>
      <expression/>
      <delay>2000</delay>
    </delayer>
    <to uri="mock:result"/>
  </route>
</camelContext>