Skip to content

Commit 1317215

Browse files
garyrussellartembilan
authored andcommitted
GH-846: Fix send and receive with confirms
Fixes #846 Send and receive with a direct container (the default) fails on the second operation because the template is not registered as a listener with the callback channel. `doSendAndReceiveWithDirect` does not invoke `doSendAndReceiveAsListener` within `execute` because the channel is obtained from the container. The first send and receive succeeds because `execute` is invoked once in the `useDirectReplyTo` which determines whether the broker supports direct reply-to. `addListener()` is called from `execute()` after a channel has been received from the cache. Fix is to call `addListener()` from `doSendAndReceiveWithDirect`. **cherry-pick to 2.0.x** # Conflicts: # spring-rabbit/src/test/java/org/springframework/amqp/rabbit/core/RabbitTemplatePublisherCallbacksIntegrationTests3.java
1 parent 381cf24 commit 1317215

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

spring-rabbit/src/main/java/org/springframework/amqp/rabbit/core/RabbitTemplate.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1661,8 +1661,11 @@ private Message doSendAndReceiveWithDirect(String exchange, String routingKey, M
16611661
}
16621662
ChannelHolder channelHolder = container.getChannelHolder();
16631663
try {
1664-
return doSendAndReceiveAsListener(exchange, routingKey, message, correlationData,
1665-
channelHolder.getChannel());
1664+
Channel channel = channelHolder.getChannel();
1665+
if (this.confirmsOrReturnsCapable) {
1666+
addListener(channel);
1667+
}
1668+
return doSendAndReceiveAsListener(exchange, routingKey, message, correlationData, channel);
16661669
}
16671670
catch (Exception e) {
16681671
container.releaseConsumerFor(channelHolder, false, null);

0 commit comments

Comments
 (0)