Skip to content

Commit 9242967

Browse files
garyrussellartembilan
authored andcommitted
GH-1477: Reduce Log Noise While Broker Down
Resolves #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**
1 parent 399eff9 commit 9242967

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

spring-rabbit/src/main/java/org/springframework/amqp/rabbit/listener/AbstractMessageListenerContainer.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.util.Set;
2929
import java.util.concurrent.CopyOnWriteArrayList;
3030
import java.util.concurrent.Executor;
31+
import java.util.concurrent.atomic.AtomicBoolean;
3132
import java.util.stream.Collectors;
3233

3334
import org.aopalliance.aop.Advice;
@@ -141,6 +142,8 @@ public abstract class AbstractMessageListenerContainer extends RabbitAccessor
141142

142143
private ContainerDelegate proxy = this.delegate;
143144

145+
private final AtomicBoolean logDeclarationException = new AtomicBoolean(true);
146+
144147
private long shutdownTimeout = DEFAULT_SHUTDOWN_TIMEOUT;
145148

146149
private ApplicationEventPublisher applicationEventPublisher;
@@ -1909,12 +1912,18 @@ protected synchronized void redeclareElementsIfNecessary() {
19091912
if (!this.lazyLoad && admin != null && isAutoDeclare()) {
19101913
try {
19111914
attemptDeclarations(admin);
1915+
this.logDeclarationException.set(true);
19121916
}
19131917
catch (Exception e) {
19141918
if (RabbitUtils.isMismatchedQueueArgs(e)) {
19151919
throw new FatalListenerStartupException("Mismatched queues", e);
19161920
}
1917-
logger.error("Failed to check/redeclare auto-delete queue(s).", e);
1921+
if (this.logDeclarationException.getAndSet(false)) {
1922+
this.logger.error("Failed to check/redeclare auto-delete queue(s).", e);
1923+
}
1924+
else {
1925+
this.logger.error("Failed to check/redeclare auto-delete queue(s).");
1926+
}
19181927
}
19191928
}
19201929
}

0 commit comments

Comments
 (0)