Can we have multiple subscribers for RabbitMQ queue?

我的梦境 提交于 2021-02-08 09:30:14

问题


I have the following superscription code in my c# console application to drain messages from RabbitMQ queue:

consumer = new EventingBasicConsumer(_channel);
consumer.Received += (o, e) =>
{
    //onMessageReceived()
};


consumer.Shutdown += (oo, oe) =>
{
    //Handle Subscribe event
};
_channel.BasicConsume(QueueName, false ,consumer);

I have two instances of this console application running to simulate multiple subscribers situation. I am always reeving messages to te first subscriber and second one is always idle. Can we have multiple subscribers to the same queue on RabbitMQ queue?


回答1:


Yes you can but if the console applications are consuming messages from the same queue, they are competing on each other. So the messages inside the queue will be consumed only by one of those.

If you want to have more subscribers that receive the same messages, you need to define a different queue per subscriber, bound to the exchange (where the messages are passing through) that should be fanout or topic (not direct).

More info here and here



来源:https://stackoverflow.com/questions/42351130/can-we-have-multiple-subscribers-for-rabbitmq-queue

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!