From 77dfa657ddb437c8ca97eadfd9f1808e12083fb4 Mon Sep 17 00:00:00 2001 From: Gary Russell Date: Thu, 20 Oct 2022 15:59:40 -0400 Subject: [PATCH] GH-1477: Reduce Log Noise While Broker Down Resolves https://github.com/spring-projects/spring-amqp/issues/1477 Only log the stack trace on the first failure. Tested with a Boot app and stop/start/stop the broker. **cherry-pick to 2.4.x** --- .../listener/AbstractMessageListenerContainer.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/listener/AbstractMessageListenerContainer.java b/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/listener/AbstractMessageListenerContainer.java index 28e621136..156c55c0c 100644 --- a/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/listener/AbstractMessageListenerContainer.java +++ b/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/listener/AbstractMessageListenerContainer.java @@ -28,6 +28,7 @@ import java.util.Set; import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.Executor; +import java.util.concurrent.atomic.AtomicBoolean; import java.util.stream.Collectors; import org.aopalliance.aop.Advice; @@ -147,6 +148,8 @@ public abstract class AbstractMessageListenerContainer extends RabbitAccessor private ContainerDelegate proxy = this.delegate; + private final AtomicBoolean logDeclarationException = new AtomicBoolean(true); + private long shutdownTimeout = DEFAULT_SHUTDOWN_TIMEOUT; private ApplicationEventPublisher applicationEventPublisher; @@ -1960,12 +1963,18 @@ protected synchronized void redeclareElementsIfNecessary() { if (!this.lazyLoad && admin != null && isAutoDeclare()) { try { attemptDeclarations(admin); + this.logDeclarationException.set(true); } catch (Exception e) { if (RabbitUtils.isMismatchedQueueArgs(e)) { throw new FatalListenerStartupException("Mismatched queues", e); } - logger.error("Failed to check/redeclare auto-delete queue(s).", e); + if (this.logDeclarationException.getAndSet(false)) { + this.logger.error("Failed to check/redeclare auto-delete queue(s).", e); + } + else { + this.logger.error("Failed to check/redeclare auto-delete queue(s)."); + } } } }