Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package org.springframework.boot.autoconfigure.data.elasticsearch;

import org.springframework.util.StringUtils;
import org.springframework.web.reactive.function.client.ExchangeStrategies;
import reactor.netty.http.client.HttpClient;

import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
Expand All @@ -36,10 +38,11 @@
* clients.
*
* @author Brian Clozel
* @author Jinlong Song
* @since 2.2.0
*/
@Configuration(proxyBeanMethods = false)
@ConditionalOnClass({ ReactiveRestClients.class, WebClient.class, HttpClient.class })
@ConditionalOnClass({ReactiveRestClients.class, WebClient.class, HttpClient.class})
@EnableConfigurationProperties(ReactiveRestClientProperties.class)
public class ReactiveRestClientAutoConfiguration {

Expand All @@ -51,12 +54,24 @@ 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());
}
if (properties.getMaxInMemorySize() != null) {
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();
}

private void configureTimeouts(ClientConfiguration.TerminalClientConfigurationBuilder builder,
ReactiveRestClientProperties properties) {
ReactiveRestClientProperties properties) {
PropertyMapper map = PropertyMapper.get();
map.from(properties.getConnectionTimeout()).whenNonNull().to(builder::withConnectTimeout);
map.from(properties.getSocketTimeout()).whenNonNull().to(builder::withSocketTimeout);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -62,6 +63,11 @@ public class ReactiveRestClientProperties {
*/
private Duration socketTimeout;

/**
* WebClient max in memory size
*/
private Integer maxInMemorySize;

public List<String> getEndpoints() {
return this.endpoints;
}
Expand Down Expand Up @@ -110,4 +116,11 @@ public void setSocketTimeout(Duration socketTimeout) {
this.socketTimeout = socketTimeout;
}

public Integer getMaxInMemorySize() {
return maxInMemorySize;
}

public void setMaxInMemorySize(Integer maxInMemorySize) {
this.maxInMemorySize = maxInMemorySize;
}
}