Issue
I would like to learn an easy way to requeue a RabbitMQ if an exception is thrown in an SpringBoot application.
@RabbitListener(queues = TRANSACTION_171_REQUEST_QUEUE, errorHandler = "receiverExceptionHandler" )
public void listen171RequestsQueue(Transaction171Request request) {
try {
Transaction171Response response = null;
send171Response("OK", request.getNumeroFormularioRenach());
} catch (Exception e){
//Requeue message
}
}
My code behaviour is to consume a message and take it out of the queue independing of what it happens. I would like to requeue message in RabbitMQ if an exception is thrown.
Could you help me?
I am working in a SpringBoot application with Java 11.
Solution
RabbitMQ's default behavior is to requeue when there is an unhandled exception. In your case, you could remove the try..catch block or in the catch block just re-throw the exception.
Answered By - marian150
Answer Checked By - Katrina (JavaFixing Volunteer)