I have a rabbit queue with messages for consuming. I also have a listener that can fail. The queue is configured with a dead letter exchange (along with a dead letter queue). What I want is to see an exception info in the messages sitting in the dead letter queue.
Here is how it works currently:
But what I want is to see the "java.lang.RuntimeException: corrupted message" somewhere on UI. I assume it should be a custom header?
Is it possible to, for example, put a general try-catch to my listener and enhance the headers with the exception info?
No; RabbitMQ (actually the AMQP specification) provides no mechanism for the consumer to to enhance rejected messages with additional information. The protocol only supports acknowledging or rejecting messages.
Spring AMQP, together with a retry interceptor, provides a mechanism to republish the message to a different queue (which can be the same as the DLQ) with additional information in the headers (exception stack trace etc).
See RepublishMessageRecoverer
in the section about error handling with asynchronous consumers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With