16

TL;DR: I need to "replay" dead letter messages back into their original queues once I've fixed the consumer code that was originally causing the messages to be rejected.

I have configured the Dead Letter Exchange (DLX) for RabbitMQ and am successfully routing rejected messages to a dead letter queue. But now I want to look at the messages in the dead letter queue and try to decide what to do with each of them. Some (many?) of these messages should be replayed (requeued) to their original queues (available in the "x-death" headers) once the offending consumer code has been fixed. But how do I actually go about doing this? Should I write a one-off program that reads messages from the dead letter queue and allows me to specify a target queue to send them to? And what about searching the dead letter queue? What if I know that a message (let's say which is encoded in JSON) has a certain attribute that I want to search for and replay? For example, I fix a defect which I know will allow message with PacketId: 1234 to successfully process now. I could also write a one-off program for this I suppose.

I certainly can't be the first one to encounter these problems and I'm wondering if anyone else has already solved them. It seems like there should be some sort of Swiss Army Knife for this sort of thing. I did a pretty extensive search on Google and Stack Overflow but didn't really come up with much. The closest thing I could find were shovels but that doesn't really seem like the right tool for the job.

4

1 回答 1

10

我是否应该编写一个一次性程序来读取死信队列中的消息并允许我指定一个目标队列来发送它们?

一般来说,是的。

您可以使用延迟消息交换插件的组合设置延迟重试以将消息重新发送回原始队列。

但这只会在一定间隔内自动重试,并且您可能在重试发生之前没有解决问题。

在某些情况下,这是可以的——比如当错误是由暂时不可用的外部资源引起的。

不过,在您的情况下,我相信您对创建一个处理死信的应用程序的想法是最好的方法,原因如下:

  • 您需要搜索消息,这是不可能的 RMQ
  • 这意味着您需要一个数据库来存储来自 DLX/队列的消息

因为您要从 DLX/队列中提取消息,所以您需要确保从消息中获取所有标头信息,以便在时机成熟时可以重新发布到正确的队列。

我当然不能成为第一个遇到这些问题的人,我想知道是否其他人已经解决了这些问题。

而你不是!

这个问题有很多解决方案,都归结为您建议的解决方案。

一些较大的“服务总线”实现内置了这种类型的功能。例如,我相信 NServiceBus(或它的 SaaS 版本)已经内置了这个功能——尽管我不是 100% 确定它。

如果您想进一步研究,请搜索“毒消息”一词 - 这通常是用于这种情况的术语。我通过快速搜索在谷歌上找到了一些东西,这可能会帮助你走上这条路:

希望有帮助!

于 2016-03-23T20:13:27.560 回答