diff --git a/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/core/RabbitTemplate.java b/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/core/RabbitTemplate.java index ca1858ce..3d68aff3 100644 --- a/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/core/RabbitTemplate.java +++ b/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/core/RabbitTemplate.java @@ -244,7 +244,7 @@ public class RabbitTemplate extends RabbitAccessor implements BeanFactoryAware, private boolean userCorrelationId; - private boolean usePublisherConnection; + private boolean usePublisherConnection = true; /** * Convenient constructor for use with setter injection. Don't forget to set the connection factory. diff --git a/src/reference/asciidoc/amqp.adoc b/src/reference/asciidoc/amqp.adoc index 39679c33..8b62cff8 100644 --- a/src/reference/asciidoc/amqp.adoc +++ b/src/reference/asciidoc/amqp.adoc @@ -1069,12 +1069,12 @@ Examples: The first example is a literal expression; the second obtains the `username` property from a connection factory bean in the application context. [[separate-connection]] -===== Using a Separate Connection +===== Using a Separate Connection for RabbitTemplate and Consumers -Starting with _version 2.0.2_, set the `usePublisherConnection` property to `true` to use a different connection to that used by listener containers, when possible. -This is to avoid consumers being blocked when a producer is blocked for any reason. -The `CachingConnectionFactory` now maintains a second internal connection factory for this purpose. +Starting with _version 2.1_, the `RabbitTemplate` `usePublisherConnection` property is true by default to avoid consumers being blocked when a producer is blocked for any reason. +The `CachingConnectionFactory` maintains a second internal connection factory for this purpose. If the rabbit template is running in a transaction started by the listener container, the container's channel is used, regardless of this setting. +To revert to the previous behavior of using the same connection as listener containers, set the template's property to `false`. [[sending-messages]] ==== Sending messages diff --git a/src/reference/asciidoc/whats-new.adoc b/src/reference/asciidoc/whats-new.adoc index 125b1a34..21765b44 100644 --- a/src/reference/asciidoc/whats-new.adoc +++ b/src/reference/asciidoc/whats-new.adoc @@ -18,3 +18,8 @@ RabbitMQ `ConnectionFactory` instances created by the `RabbitConnectionFactoryBe Certain classes have moved to different packages; most are internal classes and won't affect user applications. Two exceptions are `ChannelAwareMessageListener` and `RabbitListenerErrorHandler`; these interfaces are now in `org.springframework.amqp.rabbit.listener.api`. + +===== RabbitTemplate Changes + +The `RabbitTemplate` now sets `usePublisherConnection` to `true` by default. +See <> for more information.