diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/elasticsearch/ReactiveRestClientAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/elasticsearch/ReactiveRestClientAutoConfiguration.java index 8f2ff327be63..812e82455ac2 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/elasticsearch/ReactiveRestClientAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/elasticsearch/ReactiveRestClientAutoConfiguration.java @@ -29,6 +29,8 @@ import org.springframework.data.elasticsearch.client.reactive.ReactiveElasticsearchClient; import org.springframework.data.elasticsearch.client.reactive.ReactiveRestClients; import org.springframework.http.HttpHeaders; +import org.springframework.util.StringUtils; +import org.springframework.web.reactive.function.client.ExchangeStrategies; import org.springframework.web.reactive.function.client.WebClient; /** @@ -36,6 +38,7 @@ * clients. * * @author Brian Clozel + * @author Jinlong Song * @since 2.2.0 */ @Configuration(proxyBeanMethods = false) @@ -51,6 +54,15 @@ public ClientConfiguration clientConfiguration(ReactiveRestClientProperties prop if (properties.isUseSsl()) { builder.usingSsl(); } + if (!StringUtils.isEmpty(properties.getUsername()) || !StringUtils.isEmpty(properties.getPassword())) { + builder.withBasicAuth(properties.getUsername(), properties.getPassword()); + } + builder.withWebClientConfigurer((webClient) -> { + ExchangeStrategies exchangeStrategies = ExchangeStrategies.builder() + .codecs((configurer) -> configurer.defaultCodecs().maxInMemorySize(properties.getMaxInMemorySize())) + .build(); + return webClient.mutate().exchangeStrategies(exchangeStrategies).build(); + }); configureTimeouts(builder, properties); return builder.build(); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/elasticsearch/ReactiveRestClientProperties.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/elasticsearch/ReactiveRestClientProperties.java index 56d80b10c527..4a6bb505974f 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/elasticsearch/ReactiveRestClientProperties.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/elasticsearch/ReactiveRestClientProperties.java @@ -27,6 +27,7 @@ * Configuration properties for Elasticsearch Reactive REST clients. * * @author Brian Clozel + * @author Jinlong Song * @since 2.2.0 */ @ConfigurationProperties(prefix = "spring.data.elasticsearch.client.reactive") @@ -62,6 +63,11 @@ public class ReactiveRestClientProperties { */ private Duration socketTimeout; + /** + * WebClient max in memory size. + */ + private int maxInMemorySize = -1; + public List getEndpoints() { return this.endpoints; } @@ -110,4 +116,12 @@ public void setSocketTimeout(Duration socketTimeout) { this.socketTimeout = socketTimeout; } + public int getMaxInMemorySize() { + return this.maxInMemorySize; + } + + public void setMaxInMemorySize(int maxInMemorySize) { + this.maxInMemorySize = maxInMemorySize; + } + }