GH-1038: RT: Fix evaluatedFastReplyTo
Fixes https://github.com/spring-projects/spring-amqp/issues/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
This commit is contained in:
committed by
Artem Bilan
parent
ff8a5da5fa
commit
47c5baa666
@@ -37,6 +37,7 @@ import java.util.concurrent.TimeUnit;
|
||||
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;
|
||||
@@ -839,11 +840,13 @@ public class RabbitTemplate extends RabbitAccessor implements BeanFactoryAware,
|
||||
}
|
||||
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()) {
|
||||
|
||||
@@ -18,7 +18,9 @@ package org.springframework.amqp.rabbit.core;
|
||||
|
||||
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;
|
||||
@@ -28,6 +30,7 @@ import static org.mockito.ArgumentMatchers.anyString;
|
||||
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;
|
||||
@@ -49,6 +52,7 @@ import org.junit.rules.ExpectedException;
|
||||
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;
|
||||
@@ -63,6 +67,7 @@ import org.springframework.amqp.rabbit.connection.SingleConnectionFactory;
|
||||
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;
|
||||
@@ -227,6 +232,23 @@ public class RabbitTemplateTests {
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user