You cannot do it like this (false by default).
To do this selectively, you need to set defaultRequeueRejected to true and throw AmqpRejectAndDontRequeueRejected for any that you want to drop.
You can encapsulate the desired logic in the ErrorHandler .
The default error handler does just that for a specific list of exceptions, as it is documented here - you can introduce a custom FatalExceptionStrategy .
But for conditional rejection, defaultRequeueRejected must be true .
EDIT
factory.setErrorHandler(new ConditionalRejectingErrorHandler(t -> { Throwable cause = t.getCause(); return cause instanceof MessageConversionException || cause instanceof org.springframework.messaging.converter.MessageConversionException || cause instanceof MethodArgumentNotValidException || cause instanceof MethodArgumentTypeMismatchException || cause instanceof NoSuchMethodException || cause instanceof ClassCastException || cause instanceof MyBadXMLException; }));
This adds MyBadXMLException to the standard list.
If you are not using Java 8, use new FatalExceptionStrategy() {...} .
source share