简体   繁体   English

RabbitMQ-多个消费者的单个发布者

[英]RabbitMQ - multiple consumers single publisher

When using RabbitMQ to handle heavy messages, i need to add more than one consumer for the same publisher and task. 使用RabbitMQ处理沉重的消息时,我需要为同一发布者和任务添加一个以上的使用者。 Most of the tutorials from RabbitMQ and across the web suggest to register multiple consumers for that task (Although most of them opens a new process for each consumer in a new shell, and mine would all go under the same application). RabbitMQ和网络上的大多数教程都建议为该任务注册多个使用方(尽管它们中的大多数都在新的外壳中为每个使用方打开了一个新流程,并且我的所有操作都将在同一应用程序下进行)。 Given that every consumer needs it's own channel (correct me if i'm wrong here), that means that for X consumers we would have X channels open. 鉴于每个消费者都需要自己的渠道(如果我在这里错了,请纠正我),这意味着对于X个消费者,我们将打开X个渠道。
The alternative that comes to mind is having one consumer that ships the messages to a Thread pool containing tasks that implement the heavy work from the messages, which is a little more clumsy but requires only one open channel. 想到的另一种选择是让一个使用者将消息传送到线程池,该线程池包含执行消息中繁重工作的任务,这虽然有点笨拙,但只需要一个开放通道。
Is there a preferable way to implement this out of these two options? 在这两个选项中是否有实现此目的的更好方法? Is there a third option? 还有第三种选择吗?

Yes, every consumer needs its own channel. 是的,每个消费者都需要自己的渠道。 Your best option is to run each consumer in its own thread, with its own connection and channel. 最好的选择是在每个使用者中使用各自的连接和通道在各自的线程中运行。 RabbitMQ will round-robin delivery of messages to consumers. RabbitMQ将循环传递消息给消费者。 Be sure to read about prefetch (QoS). 请务必阅读有关预取(QoS)的信息。


NOTE: the RabbitMQ team monitors the rabbitmq-users mailing list and only sometimes answers questions on StackOverflow. 注意: RabbitMQ团队监视rabbitmq-users邮件列表 ,仅在某些情况下回答关于StackOverflow的问题。

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

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