From 09a3d4b4a8888985986e78bbfab067cc6a0aa836 Mon Sep 17 00:00:00 2001 From: Gary Russell Date: Thu, 22 Feb 2018 12:09:34 -0500 Subject: [PATCH] GH-128: Fix connection factory destruction Fixes https://github.com/spring-cloud/spring-cloud-stream-binder-rabbit/issues/128 The binder incorrectly shuts down the connection factory `@Bean`, before the bindings are stopped, preventing the container waiting for tasks to complete. Code was added to destroy the CF in the case where we create one locally, which is correct, but we should not destroy the CF managed by Spring. Also see https://jira.spring.io/browse/AMQP-800 (cherry picked from commit eaad4d9) --- .../stream/binder/rabbit/RabbitMessageChannelBinder.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/spring-cloud-stream-binder-rabbit/src/main/java/org/springframework/cloud/stream/binder/rabbit/RabbitMessageChannelBinder.java b/spring-cloud-stream-binder-rabbit/src/main/java/org/springframework/cloud/stream/binder/rabbit/RabbitMessageChannelBinder.java index 0eb4abc0c..430bd229a 100644 --- a/spring-cloud-stream-binder-rabbit/src/main/java/org/springframework/cloud/stream/binder/rabbit/RabbitMessageChannelBinder.java +++ b/spring-cloud-stream-binder-rabbit/src/main/java/org/springframework/cloud/stream/binder/rabbit/RabbitMessageChannelBinder.java @@ -125,6 +125,8 @@ public class RabbitMessageChannelBinder private final RabbitProperties rabbitProperties; + private boolean destroyConnectionFactory; + private ConnectionFactory connectionFactory; private ConnectionFactory producerConnectionFactory; @@ -207,13 +209,16 @@ public class RabbitMessageChannelBinder this.rabbitProperties.getSsl().getTrustStore(), this.rabbitProperties.getSsl().getKeyStorePassword(), this.rabbitProperties.getSsl().getTrustStorePassword()); + this.destroyConnectionFactory = true; } } @Override public void destroy() throws Exception { if (this.connectionFactory instanceof DisposableBean) { - ((DisposableBean) this.connectionFactory).destroy(); + if (this.destroyConnectionFactory) { + ((DisposableBean) this.connectionFactory).destroy(); + } ((DisposableBean) this.producerConnectionFactory).destroy(); } }