AMQP-847: Close channel in RabbitTemplate.receive
JIRA: https://jira.spring.io/browse/AMQP-847 To avoid unacked messages race condition when client timeouts, but at this moment the message becomes available in queue, physically close a receive channel on the `TimeoutException` from the `Future.get()` **Cherry-pick to 2.0.x & 1.7.x**
This commit is contained in:
committed by
Gary Russell
parent
c20e216f1c
commit
41a61eb4de
@@ -890,6 +890,7 @@ public class RabbitTemplate extends RabbitAccessor implements BeanFactoryAware,
|
||||
}
|
||||
channel.basicCancel(consumer.getConsumerTag());
|
||||
if (delivery == null) {
|
||||
RabbitUtils.setPhysicalCloseRequired(channel, true);
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
@@ -1029,6 +1030,9 @@ public class RabbitTemplate extends RabbitAccessor implements BeanFactoryAware,
|
||||
}
|
||||
receiveMessage = buildMessageFromDelivery(delivery);
|
||||
}
|
||||
else {
|
||||
RabbitUtils.setPhysicalCloseRequired(channel, true);
|
||||
}
|
||||
}
|
||||
if (receiveMessage != null) {
|
||||
Object receive = receiveMessage;
|
||||
|
||||
@@ -47,6 +47,7 @@ import java.io.UnsupportedEncodingException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.Callable;
|
||||
@@ -348,6 +349,14 @@ public class RabbitTemplateIntegrationTests {
|
||||
assertNull(this.template.receive(ROUTE));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReceiveTimeoutRequeue() {
|
||||
assertNull(this.template.receiveAndConvert(ROUTE, 1));
|
||||
assertEquals(0,
|
||||
TestUtils.getPropertyValue(this.connectionFactory, "cachedChannelsNonTransactional", List.class)
|
||||
.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReceiveBlockingTx() throws Exception {
|
||||
this.template.convertAndSend(ROUTE, "blockTX");
|
||||
|
||||
Reference in New Issue
Block a user