-
Notifications
You must be signed in to change notification settings - Fork 10
PushMessageEvent
恒宇少年 edited this page Sep 10, 2020
·
2 revisions
由于消息管道(MessagePipe
)是基于 Redis 实现的,所以拥有一些Redis内的特性,比如:KeyspaceEvent
,我们可以监听消息管道队列的写入、读取或者其他的相关事件。
每当有消息写入任意消息管道时,触发该事件。
参数:
- pipeName:消息管道名称。
- 可以大约统计消息管道的消息速率
- 可以做一些敏感消息管道的邮件通知
- ...
/**
* 消息写入管道事件{@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
这两个接口来实现。
- Server
- Client