简体   繁体   English

RabbitMQ - 如何配置条件 DLX?

[英]RabbitMQ - How to configure conditional DLX?

I have active queue which will have all messages from Publisher.我有活动队列,其中包含来自发布者的所有消息。 My Consumer reads those message and Acks/Nacks depending on the message processing result.我的消费者根据消息处理结果读取这些消息和确认/确认。

while (true)
{
   var ea = (BasicDeliverEventArgs)consumer.Queue.Dequeue();

   var body = ea.Body;
   var message = Encoding.UTF8.GetString(body);

   var processed = ProcessMessage(message)

   if (processed)                        
      channel.BasicAck(deliveryTag: ea.DeliveryTag, multiple: false);
   else
      channel.BasicNack(deliveryTag: ea.DeliveryTag, multiple: false, requeue: true);
}

My questions are我的问题是

  • Is setting true for requeue parameter when it is nacked correct?requeue参数被正确设置时,它是否设置为true
  • Or do we need to create another queue for Retry?还是我们需要为重试创建另一个队列?
  • Let us say, if I want to move the message to DLX after retrying for 10 times?让我们说,如果我想在重试 10 次后将消息移动到 DLX? How do I do it?我该怎么做? Is it C# code or can a rule be defined on the queue?是 C# 代码还是可以在队列上定义规则?
  • How do I know that a message is retried for 10 times?我怎么知道一条消息重试了 10 次? Does RabbitMQ provide any mechanism or do I need to manually design message object to contain retry count? RabbitMQ 是否提供任何机制,或者我是否需要手动设计消息对象以包含重试计数?

Thanks for your inputs感谢您的投入

Starting with release 3.5.2, RabbitMQ automatically adds a header to dead-letterred messages with informations such as:从版本 3.5.2 开始,RabbitMQ 会自动向死信消息添加标头,其中包含以下信息:

  • the queue(s) which saw the message看到消息的队列
  • the reason(s) it was dead-letterred死信的原因
  • the number of times it was dead-letterred死信的次数
  • timestamps时间戳

Look at the "Dead-Lettered Messages" section near the end of the DLX documentation for more details.有关更多详细信息,请查看DLX 文档末尾附近“死信消息”部分

If you use an older version of RabbitMQ, then @Franklin's solution should work.如果您使用旧版本的 RabbitMQ,那么@Franklin 的解决方案应该可以工作。

if you set requeue to false then it will go to any DeadLetter Exchange assigned to the Queue.如果您将 requeue 设置为 false,那么它将转到分配给队列的任何 DeadLetter Exchange。 True will requeue the message. True 将重新排队消息。

What I have done for retry attempts is to Create a Hold Exchange and Queue.我为重试所做的工作是创建一个保留交换和队列。 If you want to retry a message Return a positive Ack to the Queue, Add a RetryAttepmts Header to the Message then Publish it to the HoldQueue Exchange with a timeout value.如果要重试消息向队列返回肯定的 Ack,请向消息添加 RetryAttepmts 标头,然后将其发布到具有超时值的 HoldQueue Exchange。 Set the Hold Queue Dead Letter Exchange to an exchange that will send the message to the original Queue.将保留队列死信交换设置为将消息发送到原始队列的交换。 Then Check the header and nack if the retry attempts are too large.如果重试尝试太大,则检查标头和 nack。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM