Skip to content

Commit 1199b7c

Browse files
committed
Merge pull request #20205 from wonwoo
* wonwoo/master: Polish Configure codec buffer size in ES Reactive Rest client Closes gh-20205
2 parents 2815e6e + bbbf8c5 commit 1199b7c

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/codec/CodecProperties.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ public class CodecProperties {
3535

3636
/**
3737
* Limit on the number of bytes that can be buffered whenever the input stream needs
38-
* to be aggregated. By default this is not set, in which case individual codec
38+
* to be aggregated. This applies only to the auto-configured WebFlux server and
39+
* WebClient instances. By default this is not set, in which case individual codec
3940
* defaults apply. Most codecs are limited to 256K by default.
4041
*/
4142
private DataSize maxInMemorySize;

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/elasticsearch/ReactiveRestClientAutoConfiguration.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -29,6 +29,8 @@
2929
import org.springframework.data.elasticsearch.client.reactive.ReactiveElasticsearchClient;
3030
import org.springframework.data.elasticsearch.client.reactive.ReactiveRestClients;
3131
import org.springframework.http.HttpHeaders;
32+
import org.springframework.util.unit.DataSize;
33+
import org.springframework.web.reactive.function.client.ExchangeStrategies;
3234
import org.springframework.web.reactive.function.client.WebClient;
3335

3436
/**
@@ -52,6 +54,7 @@ public ClientConfiguration clientConfiguration(ReactiveRestClientProperties prop
5254
builder.usingSsl();
5355
}
5456
configureTimeouts(builder, properties);
57+
configureExchangeStrategies(builder, properties);
5558
return builder.build();
5659
}
5760

@@ -67,6 +70,19 @@ private void configureTimeouts(ClientConfiguration.TerminalClientConfigurationBu
6770
});
6871
}
6972

73+
private void configureExchangeStrategies(ClientConfiguration.TerminalClientConfigurationBuilder builder,
74+
ReactiveRestClientProperties properties) {
75+
PropertyMapper map = PropertyMapper.get();
76+
builder.withWebClientConfigurer((webClient) -> {
77+
ExchangeStrategies exchangeStrategies = ExchangeStrategies.builder()
78+
.codecs((configurer) -> map.from(properties.getMaxInMemorySize()).whenNonNull()
79+
.asInt(DataSize::toBytes)
80+
.to((maxInMemorySize) -> configurer.defaultCodecs().maxInMemorySize(maxInMemorySize)))
81+
.build();
82+
return webClient.mutate().exchangeStrategies(exchangeStrategies).build();
83+
});
84+
}
85+
7086
@Bean
7187
@ConditionalOnMissingBean
7288
public ReactiveElasticsearchClient reactiveElasticsearchClient(ClientConfiguration clientConfiguration) {

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/elasticsearch/ReactiveRestClientProperties.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -22,6 +22,7 @@
2222
import java.util.List;
2323

2424
import org.springframework.boot.context.properties.ConfigurationProperties;
25+
import org.springframework.util.unit.DataSize;
2526

2627
/**
2728
* Configuration properties for Elasticsearch Reactive REST clients.
@@ -62,6 +63,12 @@ public class ReactiveRestClientProperties {
6263
*/
6364
private Duration socketTimeout;
6465

66+
/**
67+
* Limit on the number of bytes that can be buffered whenever the input stream needs
68+
* to be aggregated.
69+
*/
70+
private DataSize maxInMemorySize;
71+
6572
public List<String> getEndpoints() {
6673
return this.endpoints;
6774
}
@@ -110,4 +117,12 @@ public void setSocketTimeout(Duration socketTimeout) {
110117
this.socketTimeout = socketTimeout;
111118
}
112119

120+
public DataSize getMaxInMemorySize() {
121+
return this.maxInMemorySize;
122+
}
123+
124+
public void setMaxInMemorySize(DataSize maxInMemorySize) {
125+
this.maxInMemorySize = maxInMemorySize;
126+
}
127+
113128
}

0 commit comments

Comments
 (0)