|
对于最新稳定版本,请使用Spring AMQP 4.0.0! |
经纪事件监听器
当启用事件交换插件时,如果你添加了一个类型的豆子BrokerEventListener在应用上下文中,它发布选定的经纪人事件为经纪活动实例,可以用普通的Spring消耗ApplicationListener或@EventListener方法。
事件由经纪人发布到主题交易所amq.rabbitmq.event。每种事件类型都有不同的路由密钥。
监听者使用事件键,用于绑定匿名队列切换到交换中,听者只能接收选定的事件。
由于是话题交换,可以使用万用符(也可以明确请求特定事件),如下示例所示:
@Bean
public BrokerEventListener eventListener() {
return new BrokerEventListener(connectionFactory(), "user.deleted", "channel.#", "queue.#");
}
你可以通过使用正常的春季技术进一步缩小单个事件听众接收到的事件范围,如下示例所示:
@EventListener(condition = "event.eventType == 'queue.created'")
public void listener(BrokerEvent event) {
...
}