gpt4 book ai didi

c# - 带有手动 ack 抛出 "Shared Queue Closed"的 RabbitMQ

转载 作者:太空宇宙 更新时间:2023-11-03 10:34:40 24 4
gpt4 key购买 nike

下面的消费者代码(与工作示例相距不远)在单个消息被 nacked 的几次迭代后抛出 System.IO.EndOfStreamException(“SharedQueue 关闭”)。

public void Consume ()
{
using (var connection = connectionFactory.CreateConnection ()) {
using (var channel = connection.CreateModel ()) {

channel.QueueDeclare (queueName, true, false, false, null);

// 0= “Dont send me a new message untill I’ve finshed”,
// 1= “Send me one message at a time”
channel.BasicQos (0, 1, false);
var consumer = new QueueingBasicConsumer (channel);
channel.BasicConsume (queueName, false, consumer);

Console.WriteLine (" [*] Waiting for messages. " +
"To exit press CTRL+C");

while (true) {
BasicDeliverEventArgs ea;
try {
// block until a message can be dequeue
ea = (BasicDeliverEventArgs)consumer.Queue.Dequeue ();

var body = ea.Body;
Console.WriteLine (" [x] Received, executing");

T thing = messageSerializer.Deserialize<T> (body);

try {
executor.DynamicInvoke (thing);
} catch {
channel.BasicNack (ea.DeliveryTag, false, true);
}
}

channel.BasicAck (ea.DeliveryTag, false);
} catch (OperationCanceledException) {
logger.Error ("Bugger");
}
}
}
}

我已经阅读了一些谷歌搜索结果,但 AKAIK 这通常发生在流由于设置自动确认时手动确认而关闭时?

提前致谢。

最佳答案

呸!我想我会把这个问题留在原地,以防其他人像我一样愚蠢。请注意,在上面的代码中,BasicNack 将发生,然后将继续执行 Nack 操作。这是问题的(明显的)原因。我需要打屁股。

关于c# - 带有手动 ack 抛出 "Shared Queue Closed"的 RabbitMQ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28275409/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com