Reputation: 886
I have two consumers declared in the following way:
IConnectionFactory connectionFactory = new ConnectionFactory()
{
HostName = Hostname,
UserName = Username,
Password = Password
};
Connection = connectionFactory.CreateConnection();
Channel = Connection.CreateModel();
Channel.ExchangeDeclare(
exchange: Exchange,
type: ExchangeType.Direct,
durable: true,
autoDelete: false,
arguments: null);
Channel.QueueDeclare(
queue: Queue,
durable: true,
exclusive: false,
autoDelete: false,
arguments: null);
Channel.QueueBind(Queue, Exchange, RoutingKey);
EventingBasicConsumer consumer = new EventingBasicConsumer(Channel);
consumer.Received += (model, basicDeliverEventArgs) => RecievedMessageEvent(model, basicDeliverEventArgs);
Channel.BasicConsume(
queue: Queue,
noAck: true,
consumer: consumer);
And one client declared with:
IConnectionFactory connectionFactory = new ConnectionFactory()
{
HostName = HostName,
UserName = UserName,
Password = Password
};
IConnection connection = connectionFactory.CreateConnection();
Channel = connection.CreateModel();
Channel.ExchangeDeclare(
exchange: Exchange,
type: ExchangeType.Direct,
durable: true,
autoDelete: false,
arguments: null);
Channel.QueueDeclare(
queue: Queue,
durable: true,
exclusive: false,
autoDelete: false,
arguments: null);
I am providing the same Hostname, Username, Password, Queue Name and Exchange Name to all 3 applications.
I would like to have one of the consumers processing messages with a specific Routing Key, and the other one processing the other Routing Key, for that, in the client when I send a message I do:
Channel.BasicPublish(
exchange: Exchange,
routingKey: RoutingKey,
basicProperties: null,
body: executionByteArray);
Where the Routing Key takes the value I want, in my case I am using INFO and ERROR.
Now, each one of the consumers I declared previously is declared with a specific Routing Key, that I indicate in the BasicPublish
, but... when I check my consumers they are not respecting the Routing Key, they are still consuming all the messages using a Round Robin delivery system...
I think that I might be declaring something wrong... I was trying to follow this tutorial from Rabbit MQ website: https://www.rabbitmq.com/tutorials/tutorial-four-dotnet.html
Does anyone knows what I am doing wrong?
Upvotes: 1
Views: 1329
Reputation: 1479
I am providing the same Hostname, Username, Password, Queue Name and Exchange Name to all 3 applications.
Right now you have one queue, with two bindings to the exchange. So INFO and ERROR go to your single queue which is being consumed by your two consumers.
Each consumer needs a different queue. So you need one exchange and two queues. One queue for each consumer.
Upvotes: 3