Reputation: 2149
Can you please suggest a way to add the exception to my original message header before sending it to DLQ with DLX policy in RabbitMQ
i tried to do it with aspect but my altered message is not the one pushed to DLQ, which is normal, the original message in the broker is always published instead.
@Service
@RabbitListener(queues = "queueName")
public class Listener {
@RabbitHandler
public void receive(BasicMessage message) {
try {
doSomeWork();
} catch(Exception e) {
}
}
}
Upvotes: 1
Views: 1476
Reputation: 174664
The message has to be republished programmatically; you can't modify the message if the broker just re-routes it to the DLQ.
The framework provides a mechanism to do this.
See the documentation.
The
RepublishMessageRecoverer
publishes the message with additional information in message headers, such as the exception message, stack trace, original exchange, and routing key. Additional headers can be added by creating a subclass and overridingadditionalHeaders()
. ThedeliveryMode
(or any other properties) can also be changed in theadditionalHeaders()
.
Upvotes: 2