将死队列消息移回主队列时如何防止无限循环?

How to prevent infinite loop when moving dead-queue messages back to the main queue?

我有一个死信队列,其中包含 requeue=false 的失败消息。 我通过 RabbitOperations.receiveAndConvert(failedQueueName)RabbitOperations.convertAndSend(msg) 以编程方式将消息从死队列移回主队列。有没有一种方法可以防止无限循环,而无需在将死队列消息移至主队列之前使用临时队列来保存我的死队列消息?

RabbitMQ中的Deal-Leterring添加x-death头:

This array contains an entry for each dead lettering event, identified by a pair of {queue, reason}.

这个有一个 count 字段:

how many times this message was dead-lettered in this queue for this reason

所以,我确定您可以向您的死信队列消费者添加 filtering 以丢弃已经 count 不需要的消息。