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)
This commit is contained in:
Gary Russell
2018-02-22 12:09:34 -05:00
committed by Artem Bilan
parent 8ff1fb1513
commit 09a3d4b4a8

View File

@@ -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();
}
}