Search code examples
spring-bootrabbitmqspring-rabbit

DirectMessageListenerContainer prints stack trace when Retry Policy Exhausted


Looking at the source code for class org.springframework.amqp.rabbit.listener.DirectMessageListenerContainer inside of the callExecuteListener(Message message, long deliveryTag) method, the following happens

  1. executeListener(getChannel(), message); is called
  2. If an exception is thrown, the logger prints the following message with the stack trace logger.error("Failed to invoke listener", e);

I don't need the stack trace to pollute the log in situations of AmqpRejectAndDontRequeueException thrown because my Retry Policy has been Exhausted, however I do want the stack traces for other exceptions.

I dont see an easy mechanism to override this behavior. What options do I have besides turning off logging completely for DirectMessageListenerContainer or writting a slf4j filter? Am I overlooking something?


Solution

  • No, you don't miss anything. We recently added this there though:

    if (causeChainHasImmediateAcknowledgeAmqpException(e)) {
                    if (this.logger.isDebugEnabled()) {
                        this.logger.debug("User requested ack for failed delivery: " + deliveryTag);
                    }
                    handleAck(deliveryTag, channelLocallyTransacted);
                }
    

    So, I think we could improve the logic there to skip an AmqpRejectAndDontRequeueException as well.

    Feel free to raise a JIRA ticket on the matter. Also contribution is welcome!