Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Override SimpleMessageListenerContainer.setDefaultRequeueRejected(false) behavior

We have been using a framework to use Spring AMQP , where the framework has set the SimpleMessageListenerContainer.setDefaultRequeueRejected(false),

Which means default messages will not be Requeued if throwing an exception from consumer .

Is there any way i can change this behavior without changing the SimpleMessageListenerContainer.setDefaultRequeueRejected(true)

like image 889
Akshat Avatar asked Jun 28 '26 22:06

Akshat


1 Answers

If you mean can you set the container to not requeue by default but requeue for some exception, the only way you can do that is to set defaultRequeueRejected to true (the default) and use a custom error handler.

The default ConditionalRejectingErrorHandler is configured with a default FatalExceptionStrategy that treats certain unrecoverable exceptions as fatal (message conversion exceptions etc). When these exceptions are thrown the message is rejected and not requeued.

You can provide a custom FatalExceptionStrategy to the error handler and (since version 1.6.3) inject an instance of a subclass of ConditionalRejectingErrorHandler.DefaultExceptionStrategy and implement isUserCauseFatal() - this allows you to decide which exceptions are fatal (reject and don't requeue) and which should be requeued. The error handler achieves this by throwing AmqpRejectAndDontRequeueException which is a signal to the container to not requeue the message.

Prior to 1.6.3, you had to inject a complete implementation of FatalExceptionStrategy.

like image 61
Gary Russell Avatar answered Jul 01 '26 21:07

Gary Russell



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!