有没有办法在 Spring 中使用 ApplicationEventPublisher 和延迟事件?

Is there a way to use ApplicationEventPublisher with delayed event in Spring?

我需要使用事件驱动机制。使用 ApplicationEventPublisher。我想在到达侦听此事件的端点之前为消息设置延迟。有这样的方法吗?找到 https://docs.spring.io/spring-integration/docs/2.0.0.RC1/reference/html/delayer.html 但不确定它应该如何与 ApplicationEventPublisher 集成。

有没有简单的方法可以用spring实现上面的效果?

除了 Delayer 之外,Spring 集成还提供 ApplicationEventPublishingMessageHandler 以根据传入消息生成 ApplicationEventApplicationEventPublisher。这样你真的会延迟 <delayer> 中的消息(事件),然后通过 <int-event:outbound-channel-adapter>.

将事件发布到应用程序

也考虑尽量晚用Spring集成版本:https://projects.spring.io/spring-integration/