Gh 586 loadbalancer starter (#599)

* Add loadbalancer starter. Add property to set BlockingLoadBalancerClient
as default non-reactive loadbalancer. Start working on auto-enabling caching.

* Automatically enable caching. Fixes gh-585.

* Add tests.

* Add reference docs.

* Change property name.
This commit is contained in:
Olga Maciaszek-Sharma
2019-09-09 17:49:46 +02:00
committed by GitHub
parent 8368c10865
commit 19bab039a9
10 changed files with 209 additions and 17 deletions

View File

@@ -371,12 +371,13 @@ See {githubroot}/spring-cloud-netflix/blob/master/spring-cloud-netflix-ribbon/sr
IMPORTANT: In order to use a load-balanced `RestTemplate`, you need to have a load-balancer implementation in your classpath.
The recommended implementation is `BlockingLoadBalancerClient`
- add `org.springframework.cloud:spring-cloud-loadbalancer` in order to use it.
- add `org.springframework.cloud:spring-cloud-starter-loadbalancer` in order to use it.
The
`RibbonLoadBalancerClient` also can be used, but it's now under maintenance and we do not recommend adding it to new projects.
WARNING: If you want to use `BlockingLoadBalancerClient`, make sure you do not have
`RibbonLoadBalancerClient` in the project classpath, as for backward compatibility reasons, it will be used by default.
WARNING: If you have both `RibbonLoadBalancerClient` and `BlockingLoadBalancerClient`, in order to
preserve backward compatibility, `RibbonLoadBalancerClient` will be used by default. In order
to override it, you can set the property `spring.cloud.loadbalancer.ribbon.enabled` to `false`.
=== Spring WebClient as a Load Balancer Client
@@ -411,17 +412,18 @@ The Ribbon client is used to create a full physical address.
IMPORTANT: If you want to use a `@LoadBalanced WebClient.Builder`, you need to have a loadbalancer
implementation in the classpath. It is recommended that you add the
`org.springframework.cloud:spring-cloud-loadbalancer` dependency to your project.
`org.springframework.cloud:spring-cloud-starter-loadbalancer` dependency to your project.
Then, `ReactiveLoadBalancer` will be used underneath.
Alternatively, this functionality will also work with spring-cloud-starter-netflix-ribbon, but the request
will be handled by a non-reactive `LoadBalancerClient` under the hood. Additionally,
spring-cloud-starter-netflix-ribbon is already in maintenance mode, so we do not recommned
spring-cloud-starter-netflix-ribbon is already in maintenance mode, so we do not recommend
adding it to new projects.
TIP: The `ReactorLoadBalancer` used underneath supports caching. If `cacheManager` is detected,
cached version of `ServiceInstanceSupplier` will be used. If not, we will retrieve instances
from discovery service without caching them. We recommend https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-caching.html[enabling caching] in your project
if you use `ReactiveLoadBalancer`.
IMPORTANT: In order to make use of the more efficient cached version of `ServiceInstanceSupplier`,
`spring-cloud-starter-loadbalancer` will *enable caching* by default.
https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-caching.html[Spring Boot Caching]
mechanism will be used under the hood. If you don't want caching to be used, you can set
the value of `spring.cache.type` to `none`.
==== Retrying Failed Requests
@@ -541,7 +543,7 @@ TIP: If you see errors such as `java.lang.IllegalArgumentException: Can not set
==== Spring WebFlux WebClient with Reactive Load Balancer
`WebClient` can be configured to use the `ReactiveLoadBalancer`.
If you add `org.springframework.cloud:spring-cloud-loadbalancer` to your project,
If you add `org.springframework.cloud:spring-cloud-starter-loadbalancer` to your project,
`ReactorLoadBalancerExchangeFilterFunction` is auto-configured if `spring-webflux` is on the classpath.
The following example shows how to configure a `WebClient` to use reactive load balancer under the hood:
@@ -568,7 +570,7 @@ The `ReactorLoadBalancerClient` is used to create a full physical address.
==== Spring WebFlux WebClient with non-reactive Load Balancer Client
If you you don't have `org.springframework.cloud:spring-cloud-loadbalancer` in your project,
If you you don't have `org.springframework.cloud:spring-cloud-starter-loadbalancer` in your project,
but you do have spring-cloud-starter-netflix-ribbon, you can still use `WebClient` with `LoadBalancerClient`. `LoadBalancerExchangeFilterFunction`
will be auto-configured if `spring-webflux` is on the classpath. Please note, however, that this is
uses a non-reactive client under the hood.