From 29c6673b2ff1e2c7823ee5c8c180e8e42d22bd38 Mon Sep 17 00:00:00 2001 From: Gary Russell Date: Thu, 10 Jun 2021 09:36:38 -0400 Subject: [PATCH] GH-1347: Fix new Sonar issues --- .../DirectMessageListenerContainer.java | 37 +++++++++++-------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/listener/DirectMessageListenerContainer.java b/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/listener/DirectMessageListenerContainer.java index dd9b1418..3a816caa 100644 --- a/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/listener/DirectMessageListenerContainer.java +++ b/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/listener/DirectMessageListenerContainer.java @@ -425,22 +425,7 @@ public class DirectMessageListenerContainer extends AbstractMessageListenerConta super.doStart(); final String[] queueNames = getQueueNames(); checkMissingQueues(queueNames); - if (isPossibleAuthenticationFailureFatal()) { - Connection connection = null; - try { - getConnectionFactory().createConnection(); - } - catch (AmqpAuthenticationException ex) { - throw ex; - } - catch (Exception ex) { // NOSONAR - } - finally { - if (connection != null) { - connection.close(); - } - } - } + checkConnect(); long idleEventInterval = getIdleEventInterval(); if (this.taskScheduler == null) { afterPropertiesSet(); @@ -469,6 +454,26 @@ public class DirectMessageListenerContainer extends AbstractMessageListenerConta } } + protected void checkConnect() { + if (isPossibleAuthenticationFailureFatal()) { + Connection connection = null; + try { + getConnectionFactory().createConnection(); + } + catch (AmqpAuthenticationException ex) { + this.logger.debug("Failed to authenticate", ex); + throw ex; + } + catch (Exception ex) { // NOSONAR + } + finally { + if (connection != null) { + connection.close(); + } + } + } + } + private void startMonitor(long idleEventInterval, final Map namesToQueues) { this.consumerMonitorTask = this.taskScheduler.scheduleAtFixedRate(() -> { long now = System.currentTimeMillis();