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 imp
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
Starting with version 1.3.2, the default ErrorHandler is now a ConditionalRejectingErrorHandler which will reject (and not requeue) messages that fail with an irrecoverable error:
o.s.amqp...MessageConversionException
o.s.messaging...MessageConversionException
o.s.messaging...MethodArgumentNotValidException
o.s.messaging...MethodArgumentTypeMismatchException
java.lang.NoSuchMethodException
java.lang.ClassCastException
The first can be thrown when converting the incoming message payload using a MessageConverter. The second may be thrown by the conversion service if additional conversion is required when mapping to a @RabbitListener method. The third may be thrown if validation (e.g. @Valid) is used in the listener and the validation fails. The fourth may be thrown if the inbound message was converted to a type that is not correct for the target method. For example, the parameter is declared as Message but Message is received.
The fifth and sixth were added in version 1.6.3.
You can customize the ErrorHandler
as needed.