Working with dead letters in RabbitMQ

TL DR: I need to β€œreplay” dead letter messages back to their original queues as soon as I correct the user code that initially causes the message to be rejected.

I configured Dead Letter Exchange (DLX) for RabbitMQ and successfully routed rejected messages into a dead letter queue. But now I want to see 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 reproduced (requested) in their original queues (available in the "x-death" headers) after correcting the violator code. But how do I do that? Should I write a one-time program that reads messages from the dead letter queue and allows me to specify the target queue for sending them? What about searching a line of dead letters? What if I know that a message (let it be said, which is encoded in JSON) has a specific attribute that I want to search and play? For example, I am fixing a defect that, as I know, will allow me to successfully process a message with PacketId: 1234. I could write a one-time program for this, I suppose.

Of course, I cannot be the first to encounter these problems, and I wonder if anyone else has solved them. It seems like there should be some kind of Swiss army knife for that kind. I did a fairly extensive search on Google and Stack Overflow, but really not very much. The closest I could find is shovels, but it really doesn't seem like the right tool for this job.

+11
source share
1 answer

Do I have to write a one-time program that reads messages from the dead letter queue and allows me to specify the target queue for sending them?

generally speaking yes.

You can configure a delayed retry to send the message back to the original queue using a combination of the delayed messaging plugin .

but this only automates retries at intervals, and you may not have fixed the problem before retries.

in some cases, this is normal - for example, when an error is caused by the fact that an external resource is temporarily unavailable.

in your case, however, I believe that your thoughts on creating an application for processing dead letters is the best way for several reasons:

  • You need to search for messages, which is impossible. RMQ
  • this means that you will need a database to store messages from the DLX / queue

since you are retrieving messages from the DLX / queue, you need to make sure that you get all the header information from the message so that you can republish to the correct queue when the time comes.

Of course, I cannot be the first to encounter these problems, and I wonder if someone else has already solved them.

and you are not!

There are many solutions to this problem, they all come down to the solution that you proposed.

Some large service bus implementations have a built-in function of this type. I believe that NServiceBus (or its SaaS version) is built-in, for example - although I'm not 100% sure about this.

if you want to understand this in more detail, look for the term "poisonous message" - this is usually the term used in this situation. I found a few things on Google with a quick search that can help you with this:

hope this helps!

+8
source

Source: https://habr.com/ru/post/1245652/


All Articles