From 9d49f20893c150a7b625d04e95dccdcde84a663a Mon Sep 17 00:00:00 2001 From: Gary Russell Date: Wed, 20 Apr 2022 15:43:16 -0400 Subject: [PATCH] GH-1452: Close Connection in checkMissingQueues Resolves https://github.com/spring-projects/spring-amqp/issues/1452 While not a problem with connection factories provided by the framework (which all ignore `close()`) the code should properly close the connection after use. **cherry-pick to 2.4.x, 2.3.x** --- .../amqp/rabbit/listener/BlockingQueueConsumer.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/listener/BlockingQueueConsumer.java b/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/listener/BlockingQueueConsumer.java index 263ac54604..d0f08d9222 100644 --- a/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/listener/BlockingQueueConsumer.java +++ b/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/listener/BlockingQueueConsumer.java @@ -554,7 +554,8 @@ private void checkMissingQueues() { Connection connection = null; // NOSONAR - RabbitUtils Channel channelForCheck = null; try { - channelForCheck = this.connectionFactory.createConnection().createChannel(false); + connection = this.connectionFactory.createConnection(); + channelForCheck = connection.createChannel(false); channelForCheck.queueDeclarePassive(queueToCheck); if (logger.isInfoEnabled()) { logger.info("Queue '" + queueToCheck + "' is now available");