Adds support for @LoadBalanced WebClient.Builder.
fixes gh-295
This commit is contained in:
@@ -393,6 +393,36 @@ The Ribbon client is used to create a full physical address. See
|
||||
{githubroot}/spring-cloud-netflix/blob/master/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/ribbon/RibbonAutoConfiguration.java[RibbonAutoConfiguration]
|
||||
for details of how the `RestTemplate` is set up.
|
||||
|
||||
=== Spring WebClient as a Load Balancer Client
|
||||
|
||||
`WebClient` can be automatically configured to use the `LoadBalancerClient`. To create a load balanced `WebClient` create a `WebClient.Builder` `@Bean` and use the `@LoadBalanced` qualifier.
|
||||
|
||||
[source,java,indent=0]
|
||||
----
|
||||
@Configuration
|
||||
public class MyConfiguration {
|
||||
|
||||
@Bean
|
||||
@LoadBalanced
|
||||
public WebClient.Builder loadBalancedWebClientBuilder() {
|
||||
return WebClient.builder();
|
||||
}
|
||||
}
|
||||
|
||||
public class MyClass {
|
||||
@Autowired
|
||||
private WebClient.Builder webClientBuilder;
|
||||
|
||||
public Mono<String> doOtherStuff() {
|
||||
return webClientBuilder.build().get().uri("http://stores/stores")
|
||||
.retrieve().bodyToMono(String.class);
|
||||
}
|
||||
}
|
||||
----
|
||||
|
||||
The URI needs to use a virtual host name (ie. service name, not a host name).
|
||||
The Ribbon client is used to create a full physical address.
|
||||
|
||||
==== Retrying Failed Requests
|
||||
|
||||
A load balanced `RestTemplate` can be configured to retry failed requests.
|
||||
|
||||
Reference in New Issue
Block a user