Skip to content

Commit

Permalink
GH-1038: RT: Fix evaluatedFastReplyTo
Browse files Browse the repository at this point in the history
Fixes #1038

Don't set `evaluatedFastReplyTo` if we didn't actually evaluate it because
the broker is down on the first request.

**cherry-pick to all 2.x; backport to 1.7.x**

# Conflicts:
#	spring-rabbit/src/test/java/org/springframework/amqp/rabbit/core/RabbitTemplateTests.java

# Conflicts:
#	spring-rabbit/src/test/java/org/springframework/amqp/rabbit/core/RabbitTemplateTests.java
  • Loading branch information
garyrussell authored and artembilan committed Jun 28, 2019
1 parent ff8a5da commit 47c5baa
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicInteger;

import org.springframework.amqp.AmqpConnectException;
import org.springframework.amqp.AmqpException;
import org.springframework.amqp.AmqpIllegalStateException;
import org.springframework.amqp.AmqpRejectAndDontRequeueException;
Expand Down Expand Up @@ -839,11 +840,13 @@ protected boolean useDirectReplyTo() {
}
if (this.replyAddress == null || Address.AMQ_RABBITMQ_REPLY_TO.equals(this.replyAddress)) {
try {
execute(channel -> {
return execute(channel -> {
channel.queueDeclarePassive(Address.AMQ_RABBITMQ_REPLY_TO);
return null;
return true;
});
return true;
}
catch (AmqpConnectException ex) {
throw ex;
}
catch (Exception e) {
if (logger.isDebugEnabled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@

import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.instanceOf;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
Expand All @@ -28,6 +30,7 @@
import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.BDDMockito.given;
import static org.mockito.BDDMockito.willReturn;
import static org.mockito.BDDMockito.willThrow;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
Expand All @@ -49,6 +52,7 @@
import org.mockito.Mockito;

import org.springframework.amqp.AmqpAuthenticationException;
import org.springframework.amqp.AmqpConnectException;
import org.springframework.amqp.core.Address;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageProperties;
Expand All @@ -63,6 +67,7 @@
import org.springframework.amqp.rabbit.support.PublisherCallbackChannel;
import org.springframework.amqp.support.converter.SimpleMessageConverter;
import org.springframework.amqp.utils.SerializationUtils;
import org.springframework.amqp.utils.test.TestUtils;
import org.springframework.context.ApplicationContext;
import org.springframework.expression.Expression;
import org.springframework.expression.spel.standard.SpelExpressionParser;
Expand Down Expand Up @@ -227,6 +232,23 @@ public void testRetry() throws Exception {
assertEquals(3, count.get());
}

@Test
public void testEvaluateDirectReplyToWithConnectException() {
org.springframework.amqp.rabbit.connection.ConnectionFactory mockConnectionFactory =
mock(org.springframework.amqp.rabbit.connection.ConnectionFactory.class);
willThrow(new AmqpConnectException(null)).given(mockConnectionFactory).createConnection();
RabbitTemplate template = new RabbitTemplate(mockConnectionFactory);

try {
template.convertSendAndReceive("foo");
}
catch (Exception ex) {
assertThat(ex, instanceOf(AmqpConnectException.class));
}

assertFalse(TestUtils.getPropertyValue(template, "evaluatedFastReplyTo", Boolean.class));
}

@Test
public void testRecovery() throws Exception {
ConnectionFactory mockConnectionFactory = mock(ConnectionFactory.class);
Expand Down

0 comments on commit 47c5baa

Please sign in to comment.