我是RabbitMq的新手,我正在尝试开发我的第一个.NET Core应用程序,该应用程序侦听两个不同的队列然后处理请求。
方案如下
在此之前,我只有一个字符串属性为“Type”的队列,并在我的MessageHandler中处理它
我的代码看起来像
try
{
connection = connectionFactory.CreateConnection();
channel = connection.CreateModel();
channel.ExchangeDeclare(local.Constants.Exchange,Constants.ExchangeDirectType,true,false,null);
channel.QueueDeclare(queue: local.Constants.Step1RequestQueue, durable: false, exclusive: false, autoDelete: false, arguments: null);
channel.QueueDeclare(queue: local.Constants.Step1ResponseQueue, durable: false, exclusive: false, autoDelete: false, arguments: null);
channel.QueueDeclare(queue: local.Constants.Step2RequestQueue, durable: false, exclusive: false, autoDelete: false, arguments: null);
var consumer = new AsyncEventingBasicConsumer(channel);
consumer.Received += Consumer2_Received;
channel.BasicConsume(queue: local.Constants.Step1RequestQueue,
autoAck: true,
consumer: consumer, noLocal: true);
Enabled = true;
}
catch (Exception ex)
{
log.Error(ex);
Enabled = false;
}
我的问题是如何设置侦听不同的队列?
我应该指定2 channel.BasicConsume
吗?