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**
This commit is contained in:
Gary Russell
2022-10-20 15:59:40 -04:00
committed by Artem Bilan
parent 2a4a0ecb6b
commit 77dfa657dd

View File

@@ -28,6 +28,7 @@ import java.util.Properties;
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 @@ public abstract class AbstractMessageListenerContainer extends RabbitAccessor
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).");
}
}
}
}