问题
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