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 3d68aff3..ca1858ce 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 = true; + private boolean usePublisherConnection; /** * 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 8b62cff8..738131ea 100644 --- a/src/reference/asciidoc/amqp.adoc +++ b/src/reference/asciidoc/amqp.adoc @@ -1069,12 +1069,17 @@ 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 for RabbitTemplate and Consumers +===== Using a Separate Connection -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. +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. 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`. + +IMPORTANT: In general, you should not use a `RabbitAdmin` with a template that has this set to true. +Use the `RabbitAdmin` constructor that takes a connection factory; if you use the other constructor that takes a template, ensure the template's property is false. +This is because, often, an admin is used to declare queues for listener containers; using a template that has the property set to true would mean that exclusive queues (such as `AnonymousQueue`) would be declared on a different connection to that used by listener containers. +In that case, the queues cannot be used by the containers. [[sending-messages]] ==== Sending messages diff --git a/src/reference/asciidoc/whats-new.adoc b/src/reference/asciidoc/whats-new.adoc index 21765b44..125b1a34 100644 --- a/src/reference/asciidoc/whats-new.adoc +++ b/src/reference/asciidoc/whats-new.adoc @@ -18,8 +18,3 @@ 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.