Closed
Description
Hi there!
When spring boot 3.2 came out, I considered switching from WebClient
to RestClient
as the first one needs all interceptors to be written in reactive style which makes them harder to support and understand.
It turns out RestClient
doesn't provide any alternates to 2 pretty important features which are present in WebClient
and which we heavily use.
- no
attribute(key, value)
method forRestClient
. That means it's not possible to pass a value from the call site into the interceptor code. Dozen of auth interceptors become impossible to implement withRestClient
. Here is how we use them withWebClient
:
myWebClient
.get()
.uri("/smth")
.attribute("token" token)
.retrieve()
// ...
// the interceptor code
public ExchangeFilterFunction authenticate() {
return (request, next) -> {
String token = request.attribute("token").get().toString();
// ...
};
}
- No single option to configure timeouts. With
WebClient
there are lots of them. An example
@Bean
WebClientCustomizer webClientGlobalTimeoutCustomizer() {
return (WebClient.Builder webClientBuilder) -> {
ConnectionProvider provider = ConnectionProvider.builder("common")
.maxIdleTime(Duration.ofSeconds(10))
.maxLifeTime(Duration.ofSeconds(60))
.pendingAcquireTimeout(Duration.ofSeconds(30))
.evictInBackground(Duration.ofSeconds(60))
.build();
HttpClient httpClient = HttpClient
.create(provider)
.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, timeoutInMillis)
.doOnConnected(conn -> conn
.addHandlerLast(new ReadTimeoutHandler(5000, TimeUnit.MILLISECONDS))
.addHandlerLast(new WriteTimeoutHandler(5000, TimeUnit.MILLISECONDS)));
webClientBuilder.clientConnector(new ReactorClientHttpConnector(httpClient));
};
}
Are those things something which is planned to be implemented in spring boot 3.3+ ? Or there some fundamental issues with RestClient
underlying implementation so no attribute()
and no timeouts?