如何处理特定时间的消息?

How to process a message in a specific time?

我正在使用 spring-集成来开发服务总线。我需要在特定时间处理来自消息存储的一些消息。例如,如果消息的有效负载中有一个 executionTimestamp 参数,它将在指定的时间执行,否则在收到消息后立即执行。 我必须使用哪种 channeltaskExecutor? 我必须实施自定义 Trigger 还是有一些常规方法来实施消息处理策略?

此致

参见the Delayer

The delay handler supports expression evaluation results that represent an interval in milliseconds (any Object whose toString() method produces a value that can be parsed into a Long) as well as java.util.Date instances representing an absolute time. In the first case, the milliseconds will be counted from the current time (e.g. a value of 5000 would delay the Message for at least 5 seconds from the time it is received by the Delayer). With a Date instance, the Message will not be released until the time represented by that Date object. In either case, a value that equates to a non-positive delay, or a Date in the past, will not result in any delay. Instead, it will be sent directly to the output channel on the original sender’s Thread. If the expression evaluation result is not a Date, and can not be parsed as a Long, the default delay (if any) will be applied.

如果您不想在服务器崩溃时丢失当前延迟的消息,您可以添加一个 MessageStore 来保存消息。