在 rabbitmq-dotnet-client 中传递 "consumer_cancel_notify" 设置为 "false" 的 ClientProperties
Passing ClientProperties with "consumer_cancel_notify" set to "false" in rabbitmq-dotnet-client
我使用基于 rabbitmq-dotnet-client 的异步 rabbitmq 消费者。
这是一个简化代码
using (_channel = RabbitMqConnectionFactory.Connection.CreateModel())
{
_channel.QueueDeclare(Constants.QueueName,
durable: true,
exclusive: false,
autoDelete: false,
arguments: null);
_channel.BasicQos(0, 1, false);
var consumer = new AsyncEventingBasicConsumer(_channel);
consumer.Received += async (o, a) =>
{
await HandleMessageEvent(o, a);
};
string tag = _channel.BasicConsume(Constants.QueueName, false, consumer);
while (IsWorking)
{
await Task.Delay(6000);
}
_channel.BasicCancel(tag);
IsWorking = false;
}
我希望 RabbitMQ 服务器 不发送 ACK 来响应 BasicCancel
消息。
根据 documentation ,我可以在建立连接时在 ClientProperties
属性 中传递参数 consumer_cancel_notify
和 false
值.
我试着用这样的代码来做。
public static ConnectionFactory GetRabbitMqConnectionFactory()
{
Dictionary<string, bool> capabilities = new Dictionary<string, bool>
{
["consumer_cancel_notify"] = false
};
var result = new ConnectionFactory
{
ContinuationTimeout = TimeSpan.FromSeconds(5),
HostName = "localhost",
UserName = "guest",
Password = "guest",
DispatchConsumersAsync = true,
ClientProperties =
{
["capabilities"] = capabilities
},
};
return result;
}
但是,这不起作用,因为服务器仍然向 BasicCancel
消息发送 ACK,我可以使用 ConsumerCancelled
AsyncEventHandled 处理。
我使用 RabbitMQ Server 版本 3.8.3 和 rabbitmq-dotnet-client 版本 5.1.2。
如何将 consumer_cancel_notify
参数传递给 RabbitMQ 代理?
在 RabbitMQ .NET 客户端 6.0.0 版中,void BasicCancelNoWait (string consumerTag)
方法已添加到 public API.
在客户端使用此方法时,服务器不会发送 ACK 来响应 BasicCancel 请求。
我使用基于 rabbitmq-dotnet-client 的异步 rabbitmq 消费者。
这是一个简化代码
using (_channel = RabbitMqConnectionFactory.Connection.CreateModel())
{
_channel.QueueDeclare(Constants.QueueName,
durable: true,
exclusive: false,
autoDelete: false,
arguments: null);
_channel.BasicQos(0, 1, false);
var consumer = new AsyncEventingBasicConsumer(_channel);
consumer.Received += async (o, a) =>
{
await HandleMessageEvent(o, a);
};
string tag = _channel.BasicConsume(Constants.QueueName, false, consumer);
while (IsWorking)
{
await Task.Delay(6000);
}
_channel.BasicCancel(tag);
IsWorking = false;
}
我希望 RabbitMQ 服务器 不发送 ACK 来响应 BasicCancel
消息。
根据 documentation ,我可以在建立连接时在 ClientProperties
属性 中传递参数 consumer_cancel_notify
和 false
值.
我试着用这样的代码来做。
public static ConnectionFactory GetRabbitMqConnectionFactory()
{
Dictionary<string, bool> capabilities = new Dictionary<string, bool>
{
["consumer_cancel_notify"] = false
};
var result = new ConnectionFactory
{
ContinuationTimeout = TimeSpan.FromSeconds(5),
HostName = "localhost",
UserName = "guest",
Password = "guest",
DispatchConsumersAsync = true,
ClientProperties =
{
["capabilities"] = capabilities
},
};
return result;
}
但是,这不起作用,因为服务器仍然向 BasicCancel
消息发送 ACK,我可以使用 ConsumerCancelled
AsyncEventHandled 处理。
我使用 RabbitMQ Server 版本 3.8.3 和 rabbitmq-dotnet-client 版本 5.1.2。
如何将 consumer_cancel_notify
参数传递给 RabbitMQ 代理?
在 RabbitMQ .NET 客户端 6.0.0 版中,void BasicCancelNoWait (string consumerTag)
方法已添加到 public API.
在客户端使用此方法时,服务器不会发送 ACK 来响应 BasicCancel 请求。