Fix CCF addresses population in Cloud profile

The Spring Boot's `RabbitProperties` populates the `host:port`
(default values) to the addresses property in the `determineAddresses()`.
This way we override provided by Cloud Connectors `host:port`

* Do not populated `addresses` to the CCF from the `RabbitProperties`
if the real `addresses` is null.
Only explicit `spring.rabbitmq.addresses` application property will have
effect

**Cherry-pick to 1.3.x**
This commit is contained in:
Artem Bilan
2018-01-03 10:03:56 -05:00
committed by Gary Russell
parent 7cf4ccca25
commit cc354cbd7d
2 changed files with 12 additions and 2 deletions

View File

@@ -39,6 +39,7 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.Primary;
import org.springframework.context.annotation.Profile;
import org.springframework.util.StringUtils;
/**
* Bind to services, either locally or in a cloud environment.
@@ -167,7 +168,10 @@ public class RabbitServiceAutoConfiguration {
static void configureCachingConnectionFactory(CachingConnectionFactory connectionFactory,
ConfigurableApplicationContext applicationContext, RabbitProperties rabbitProperties) throws Exception {
connectionFactory.setAddresses(rabbitProperties.determineAddresses());
if (StringUtils.hasText(rabbitProperties.getAddresses())) {
connectionFactory.setAddresses(rabbitProperties.determineAddresses());
}
connectionFactory.setPublisherConfirms(rabbitProperties.isPublisherConfirms());
connectionFactory.setPublisherReturns(rabbitProperties.isPublisherReturns());
if (rabbitProperties.getCache().getChannel().getSize() != null) {

View File

@@ -251,13 +251,19 @@ public class RabbitBinderModuleTests {
ConnectionFactory binderConnectionFactory = (ConnectionFactory) binderFieldAccessor
.getPropertyValue("connectionFactory");
ConnectionFactory connectionFactory = this.context.getBean(ConnectionFactory.class);
assertThat(binderConnectionFactory).isNotSameAs(connectionFactory);
ConnectionFactory producerConnectionFactory = (ConnectionFactory) binderFieldAccessor
.getPropertyValue("producerConnectionFactory");
assertThat(producerConnectionFactory).isNotSameAs(connectionFactory);
assertThat(binderConnectionFactory).isNotSameAs(connectionFactory);
assertThat(binderConnectionFactory).isNotSameAs(producerConnectionFactory);
assertThat(TestUtils.getPropertyValue(connectionFactory, "addresses")).isNotNull();
assertThat(TestUtils.getPropertyValue(binderConnectionFactory, "addresses")).isNull();
assertThat(TestUtils.getPropertyValue(producerConnectionFactory, "addresses")).isNull();
Cloud cloud = this.context.getBean(Cloud.class);