gpt4 book ai didi

c# - 重新排队后保持交货顺序

转载 作者:行者123 更新时间:2023-11-30 15:59:03 26 4
gpt4 key购买 nike

我正在开发一个使用 Rabbit MQ 进行消息传递的应用程序。我使用明确的 ACK:

model.BasicConsume(queueName,false, consumer);

并在处理完消息后做ACK:

consumer.Received += (ch, ea) =>
{
try
{
var message = Encoding.UTF8.GetString(ea.Body);

Logger.Info($"DeliveryTag={ea.DeliveryTag}, message={message}");

((EventingBasicConsumer)ch).Model.BasicAck(ea.DeliveryTag, false);

}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
};

问题是当处理消息时出现错误并且 Rabbit 没有收到 ACK,它不同的顺序将消息返回到队列

例如有消息M1、M2、M3、M4。

如果 M2 返回队列,则它将是 M3、M4、M2。

有什么方法可以保持交货顺序

附言我只有一个消费者和RabbitMQ 3.6.6,但我仍然有重新排序的问题。

最佳答案

一切都得到了回答here ,在消息排序保证下。我只是引用

Messages can be returned to the queue using AMQP methods that feature a requeue parameter (basic.recover, basic.reject and basic.nack), or due to a channel closing while holding unacknowledged messages. Any of these scenarios caused messages to be requeued at the back of the queue for RabbitMQ releases earlier than 2.7.0. From RabbitMQ release 2.7.0, messages are always held in the queue in publication order, even in the presence of requeueing or channel closure.

With release 2.7.0 and later it is still possible for individual consumers to observe messages out of order if the queue has multiple subscribers. This is due to the actions of other subscribers who may requeue messages. From the perspective of the queue the messages are always held in the publication order.

关于c# - 重新排队后保持交货顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42243926/

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