There was an error while loading. Please reload this page.
由于消息管道(MessagePipe)是基于 Redis 实现的,所以拥有一些Redis内的特性,比如:KeyspaceEvent,我们可以监听消息管道队列的写入、读取或者其他的相关事件。
MessagePipe
KeyspaceEvent
每当有消息写入任意消息管道时,触发该事件。
参数:
/** * 消息写入管道事件{@link PushMessageEvent}监听示例 * * @author 恒宇少年 */ @Component @Slf4j public class ExamplePushMessageListener implements ApplicationListener<PushMessageEvent> { @Override public void onApplicationEvent(PushMessageEvent event) { String pipeName = event.getPipeName(); log.info("消息管道:{},有新消息写入.", pipeName); } }
PushMessageEvent事件的发布方式是通过ApplicationEventPublisher,所以我们可以通过实现ApplicationListener、SmartApplicationListener这两个接口来实现。
PushMessageEvent
ApplicationEventPublisher
ApplicationListener
SmartApplicationListener