Spring Boot/RabbitMQ avoid unack msg

1.2k views Asked by At
@RabbitListener(queues="XYZ")
public void rabbitMsgReceiver(@Payload final UserProfile up, Message msg, Channel channel)  {

}

If the message that is received is not a valid JSON of UserProfile, then ListenerExecutionFailedException occurs and the message goes to the unack state. How can I send the message into the dead letter queue?

1

There are 1 answers

0
Lho Ben On

You can configure a dead letter queue policy in order to send unacked message to dlq instead of putting them to the original queue

https://www.rabbitmq.com/dlx.html#using-policies

example for your queue XYZ, suppose your set XYZ-dlq for it :

sudo rabbitmqctl set_policy XYZ-dlq "^XYZ$" '{"dead-letter-exchange":"", "dead-letter-routing-key":"XYZ-dlq"}' --apply-to queues