In what version(s) of Spring AMQP are you seeing this issue?
3.5.3
Describe the bug
This bug is about MessageRejectedWhileStoppingException
which leads to an error log being emitted which I believe should be of lower severity: info or warning (I leave that decision to the maintainers).
This bug can would be best described by @artembilan's answer to a Stack Overflow question I raised:
I'm wondering from reading the documentation whether this is an error or sort of a notification that a message was requeued, and if it's the latter, why is it logged as an error?
Yes, feels like that. Because the logic there is like this:
java /** * Determine whether a message should be requeued; returns true if the throwable is a * {@link MessageRejectedWhileStoppingException} or defaultRequeueRejected is true and * there is not an {@link AmqpRejectAndDontRequeueException} in the cause chain or if * there is an {@link ImmediateRequeueAmqpException} in the cause chain. * @param defaultRequeueRejected the default requeue rejected. * @param throwable the throwable. * @param logger the logger to use for debug. * @return true to requeue. */ public static boolean shouldRequeue(boolean defaultRequeueRejected, Throwable throwable, Log logger) { boolean shouldRequeue = defaultRequeueRejected || throwable instanceof MessageRejectedWhileStoppingException;
So, the failed to be processed message in that stopping case is indeed requeued.
Looks like there is a race condition just after we cancel consumer and such an in-flight message. So, we are > able to mark this consumer as stopped as a reaction to the
cancelOK
reply, but the last in-flight message > is still in ahandleDelivery
process.So, probably we cannot mitigate that race condition, but we indeed can fix that:
kotlin this.logger.error("Failed to invoke listener", e);
To be
info
for this specificMessageRejectedWhileStoppingException
.If that makes sense for you, please, raise a GH issue and we will fix ASAP.
It definitely makes sense to me that if this is not a very bad thing (like the message getting lost due to ungraceful shutdown), it shouldn't be logged as an error
.
I'm not sure what @artembilan is referring to when he writes "this specific MessageRejectedWhileStoppingException
" so I phrased my title defensively. I don't know if MessageRejectedWhileStoppingException
is always acceptable, or if there is a specific MessageRejectedWhileStoppingException
(that I'm definitely encountering) that is acceptable.
To Reproduce
Orderly shutdown of Spring application while messages are in flight.
Expected behavior
A clear and concise description of what you expected to happen.
Sample
N/A.