Skip to content

Commit

Permalink
RabbitTemplate: Use separate connection by default
Browse files Browse the repository at this point in the history
  • Loading branch information
garyrussell authored and artembilan committed May 11, 2018
1 parent 0fce70d commit ca09dfa
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions src/reference/asciidoc/amqp.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions src/reference/asciidoc/whats-new.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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 <<separate-connection>> for more information.

0 comments on commit ca09dfa

Please sign in to comment.