Skip to content

Commit 4165542

Browse files
garyrussellartembilan
authored andcommitted
Unconditionally Disable RMQ AutoRecovery
1 parent 17f7332 commit 4165542

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

spring-rabbit/src/main/java/org/springframework/amqp/rabbit/connection/CachingConnectionFactory.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -257,13 +257,17 @@ private CachingConnectionFactory(com.rabbitmq.client.ConnectionFactory rabbitCon
257257
super(rabbitConnectionFactory);
258258
if (!isPublisherFactory) {
259259
if (rabbitConnectionFactory.isAutomaticRecoveryEnabled()) {
260-
logger.warn("***\nAutomatic Recovery is Enabled in the provided connection factory;\n"
261-
+ "while Spring AMQP is compatible with this feature, it\n"
260+
rabbitConnectionFactory.setAutomaticRecoveryEnabled(false);
261+
logger.warn("***\nAutomatic Recovery was Enabled in the provided connection factory;\n"
262+
+ "while Spring AMQP is generally compatible with this feature, there\n"
263+
+ "are some corner cases where problems arise. Spring AMQP\n"
262264
+ "prefers to use its own recovery mechanisms; when this option is true, you may receive\n"
263-
+ "'AutoRecoverConnectionNotCurrentlyOpenException's until the connection is recovered.");
265+
+ "'AutoRecoverConnectionNotCurrentlyOpenException's until the connection is recovered.\n"
266+
+ "It has therefore been disabled; if you really wish to enable it, use\n"
267+
+ "'getRabbitConnectionFactory().setAutomaticRecoveryEnabled(true)',\n"
268+
+ "but this is discouraged.");
264269
}
265-
this.publisherConnectionFactory = new CachingConnectionFactory(getRabbitConnectionFactory(),
266-
true);
270+
this.publisherConnectionFactory = new CachingConnectionFactory(getRabbitConnectionFactory(), true);
267271
setPublisherConnectionFactory(this.publisherConnectionFactory);
268272
}
269273
else {

spring-rabbit/src/test/java/org/springframework/amqp/rabbit/connection/CachingConnectionFactoryTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -1574,6 +1574,7 @@ public void setAddressesTwoHosts() throws Exception {
15741574
ccf.setAddresses("mq1,mq2");
15751575
ccf.createConnection();
15761576
verify(mock).isAutomaticRecoveryEnabled();
1577+
verify(mock).setAutomaticRecoveryEnabled(false);
15771578
verify(mock).newConnection(isNull(),
15781579
aryEq(new Address[] { new Address("mq1"), new Address("mq2") }), anyString());
15791580
verifyNoMoreInteractions(mock);

src/reference/asciidoc/whats-new.adoc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,14 @@ See <<async-return>> for more information.
7676

7777
The `RabbitConnectionFactoryBean` now calls `enableHostnameVerification()` by default; to revert to the previous behavior, set the `enableHostnameVerification` property to `false`.
7878

79+
===== Connection Factory Changes
80+
81+
The `CachingConnectionFactory` now unconditionally disables auto recovery in the underlying RabbitMQ `ConnectionFactory`, even if a pre-configured instance is provided in a constructor.
82+
While steps have been taken to make Spring AMQP compatible with auto recovery, certain corner cases have arisen where issues remain.
83+
Spring AMQP has had its own recovery mechanism since 1.0.0 and doesn't need to use the recovery provided by the client.
84+
While it is still possible to enable the feature (using `cachingConnectionFactory.getRabbitConnectionFactory().setAutomaticRecoveryEnabled()`) after the `CachingConnectionFactory` is constructed, it is **strongly recommended that you not do so**.
85+
Use a separate RabbitMQ `ConnectionFactory` if you need auto recovery connections when using the client factory directly (rather than via Spring AMQP components).
86+
7987
===== Listener Container Changes
8088

8189
The default `ConditionalRejectingErrorHandler` will now completely discard messages that cause fatal errors if an `x-death` header is present.

0 commit comments

Comments
 (0)