Class DelayHandler

All Implemented Interfaces:
EventListener, org.reactivestreams.Subscriber<Message<?>>, Aware, BeanClassLoaderAware, BeanFactoryAware, BeanNameAware, DisposableBean, InitializingBean, ApplicationContextAware, ApplicationListener<ContextRefreshedEvent>, Ordered, ExpressionCapable, Orderable, MessageProducer, DelayHandlerManagement, HeaderPropagationAware, IntegrationPattern, NamedComponent, IntegrationManagement, TrackableComponent, MessageHandler, reactor.core.CoreSubscriber<Message<?>>

public class DelayHandler
extends AbstractReplyProducingMessageHandler
implements DelayHandlerManagement, ApplicationListener<ContextRefreshedEvent>
A MessageHandler that is capable of delaying the continuation of a Message flow based on the result of evaluation delayExpression on an inbound Message or a default delay value configured on this handler. Note that the continuation of the flow is delegated to a TaskScheduler, and therefore, the calling thread does not block. The advantage of this approach is that many delays can be managed concurrently, even very long delays, without producing a buildup of blocked Threads.

One thing to keep in mind, however, is that any active transactional context will not propagate from the original sender to the eventual recipient. This is a side-effect of passing the Message to the output channel after the delay with a different Thread in control.

When this handler's delayExpression property is configured, that evaluation result value will take precedence over the handler's defaultDelay value. The actual evaluation result value may be a long, a String that can be parsed as a long, or a Date. If it is a long, it will be interpreted as the length of time to delay in milliseconds counting from the current time (e.g. a value of 5000 indicates that the Message can be released as soon as five seconds from the current time). If the value is a Date, it will be delayed at least until that Date occurs (i.e. the delay in that case is equivalent to headerDate.getTime() - new Date().getTime()).

Mark Fisher, Artem Bilan, Gary Russell