From 4b77e2e205f46ef245cdd6f5e07ee03cd71258e0 Mon Sep 17 00:00:00 2001 From: Jonghan Kim Date: Wed, 26 Aug 2020 20:08:46 +0900 Subject: [PATCH] Add support for RabbitMQ's addressShuffleMode property See gh-23091 --- .../amqp/RabbitAutoConfiguration.java | 2 ++ .../boot/autoconfigure/amqp/RabbitProperties.java | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoConfiguration.java index 6276bf358c9..5e4e2f1e44f 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoConfiguration.java @@ -83,6 +83,7 @@ import org.springframework.context.annotation.Import; * @author Gary Russell * @author Phillip Webb * @author Artsiom Yudovin + * @author Jonghan Kim * @since 1.0.0 */ @Configuration(proxyBeanMethods = false) @@ -105,6 +106,7 @@ public class RabbitAutoConfiguration { .getObject()); PropertyMapper map = PropertyMapper.get(); map.from(properties::determineAddresses).to(factory::setAddresses); + map.from(properties::getAddressShuffleMode).whenNonNull().to(factory::setAddressShuffleMode); map.from(properties::isPublisherReturns).to(factory::setPublisherReturns); map.from(properties::getPublisherConfirmType).whenNonNull().to(factory::setPublisherConfirmType); RabbitProperties.Cache.Channel channel = properties.getCache().getChannel(); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitProperties.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitProperties.java index f2c90aa5858..c2388bae5ff 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitProperties.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitProperties.java @@ -23,6 +23,7 @@ import java.util.List; import java.util.Optional; import org.springframework.amqp.core.AcknowledgeMode; +import org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.AddressShuffleMode; import org.springframework.amqp.rabbit.connection.CachingConnectionFactory.CacheMode; import org.springframework.amqp.rabbit.connection.CachingConnectionFactory.ConfirmType; import org.springframework.boot.context.properties.ConfigurationProperties; @@ -41,6 +42,7 @@ import org.springframework.util.StringUtils; * @author Gary Russell * @author Artsiom Yudovin * @author Franjo Zilic + * @author Jonghan Kim * @since 1.0.0 */ @ConfigurationProperties(prefix = "spring.rabbitmq") @@ -87,6 +89,11 @@ public class RabbitProperties { */ private String addresses; + /** + * Shuffling mode for connecting host. + */ + private AddressShuffleMode addressShuffleMode; + /** * Requested heartbeat timeout; zero for none. If a duration suffix is not specified, * seconds will be used. @@ -282,6 +289,14 @@ public class RabbitProperties { this.virtualHost = "".equals(virtualHost) ? "/" : virtualHost; } + public AddressShuffleMode getAddressShuffleMode() { + return this.addressShuffleMode; + } + + public void setAddressShuffleMode(AddressShuffleMode addressShuffleMode) { + this.addressShuffleMode = addressShuffleMode; + } + public Duration getRequestedHeartbeat() { return this.requestedHeartbeat; }