First of all, I present context of my case:
I am using spring-boot
and spring-rabbitmq
. It is working for me, you should know that I must have implemented custom converter for received messages.
(1) From this converter can be thrown exception, for instance in case of inproper message and so on.
(2) After successfull converting (no exception) listener is invoked. Then, in the listener it can also be thrown exception.
Now, I would like to force two things:
(1') Don't requeue message in case of expcetion in converter. Simply, send acknowledgment to queue and simulate that everything is alright.
(2') What is default setting in this case ? When internal spring-rabbitmq engine
decide to send acknowledgment to queue ? When it decide command to requeue ? Is it possible to manage it in depends on situation ?
I found in docs:
If retries are not enabled and the listener throws an exception, by default the delivery will be retried indefinitely. You can modify this behavior in two ways; set the defaultRequeueRejected property to false and zero re-deliveries will be attempted; or, throw an AmqpRejectAndDontRequeueException to signal the message should be rejected. This is the mechanism used when retries are enabled and the maximum delivery attempts are reached.
For example, in depends on catched exception in listener I should decide if I would like to requeue message, as I think (simply by throwing from catch
AmqpRejectAndDontRequeueException
). I am not sure if it is good way and it is why I am asking you about your opinion.
Please read the reference manual.
The behavior is (mostly) controlled by the
ErrorHandler
.Throw a
MessageConversionException
- the container requeues messages for most exceptions but some exceptions are considered fatal. Generally, if a message can't be converted, then redelivering it makes no sense.This is all clearly explained in the section (surprisingly?) called Exception Handling
You can customize the
ErrorHandler
as needed.