简体   繁体   English

RabbitMQ 向所有消费者广播事件

[英]RabbitMQ broadcast events to all consumers

Is possible to use topic exchange as true event notification system?是否可以将topic交换用作真正的事件通知系统?

I've created topic exchange on given exchange named as Cherry .我在名为Cherry给定交换上创建了topic交换。 I've got one publisher at routing key cherry.user.created and many consumers with same routing key, but when I publish an event only one of consumers consume an event.我在路由键cherry.user.created有一个发布者,并且有许多具有相同路由键的消费者,但是当我发布一个事件时,只有一个消费者使用一个事件。 I thought that topic can be used as "real event broadcasting" - every consumer gets notified when given event happened, but right now only one consumer consume an event and other consumers do not know about created event...我认为该主题可以用作“真实事件广播” - 每个消费者在给定事件发生时都会收到通知,但现在只有一个消费者消费一个事件而其他消费者不知道创建的事件......

To clarify my comment about queues.澄清我对队列的评论。 In rabbitmq, if multiple consumers use the same queue - message delivered to that queue is always dispatched in round-robin manner, no matter what.在 rabbitmq 中,如果多个消费者使用同一个队列 - 无论如何,传递到该队列的消息总是以循环方式分派。 So when you subscribe to topic exchange, best way is to declare new queue for each consumer (with any name, or better random generated by rabbit itself) and use target routing key ( cherry.user.created ) to bind those queues to exchange.因此,当您订阅主题交换时,最好的方法是为每个消费者声明新队列(使用任何名称,或者由rabbit 本身生成更好的随机)并使用目标路由键( cherry.user.created )将这些队列绑定到交换。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM