Skip to content
Merged
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
1 change: 0 additions & 1 deletion docs/src/main/asciidoc/_configprops.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
|spring.cloud.loadbalancer.health-check.interval | 30s | Interval for rerunning the HealthCheck scheduler.
|spring.cloud.loadbalancer.health-check.path | |
|spring.cloud.loadbalancer.retry.enabled | true |
|spring.cloud.loadbalancer.ribbon.enabled | true | Causes `RibbonLoadBalancerClient` to be used by default.
|spring.cloud.refresh.enabled | true | Enables autoconfiguration for the refresh scope and associated features.
|spring.cloud.refresh.extra-refreshable | true | Additional class names for beans to post process into refresh scope.
|spring.cloud.service-registry.auto-registration.enabled | true | Whether service auto-registration is enabled. Defaults to true.
Expand Down
34 changes: 2 additions & 32 deletions docs/src/main/asciidoc/spring-cloud-commons.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -389,18 +389,10 @@ CAUTION: A `RestTemplate` bean is no longer created through auto-configuration.
Individual applications must create it.

The URI needs to use a virtual host name (that is, a service name, not a host name).
The Ribbon client is used to create a full physical address.
See {githubroot}/spring-cloud-netflix/blob/master/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/RibbonAutoConfiguration.java[`RibbonAutoConfiguration`] for the details of how the `RestTemplate` is set up.
The BlockingLoadBalancerClient is used to create a full physical address.

IMPORTANT: To use a load-balanced `RestTemplate`, you need to have a load-balancer implementation in your classpath.
The recommended implementation is `BlockingLoadBalancerClient`.
Add <<spring-cloud-loadbalancer-starter, Spring Cloud LoadBalancer starter>> to your project 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: By default, if you have both `RibbonLoadBalancerClient` and `BlockingLoadBalancerClient`, to
preserve backward compatibility, `RibbonLoadBalancerClient` is used.
To override it, you can set the `spring.cloud.loadbalancer.ribbon.enabled` property to `false`.

[[webclinet-loadbalancer-client]]
=== Spring WebClient as a Load Balancer Client
Expand Down Expand Up @@ -434,29 +426,19 @@ public class MyClass {
====

The URI needs to use a virtual host name (that is, a service name, not a host name).
The Ribbon client or Spring Cloud LoadBalancer is used to create a full physical address.
The Spring Cloud LoadBalancer is used to create a full physical address.

IMPORTANT: If you want to use a `@LoadBalanced WebClient.Builder`, you need to have a load balancer
implementation in the classpath. We recommend that you add the
<<spring-cloud-loadbalancer-starter, Spring Cloud LoadBalancer starter>> to your project.
Then, `ReactiveLoadBalancer` is used underneath.
Alternatively, this functionality also works with `spring-cloud-starter-netflix-ribbon`, but the request
is handled by a non-reactive `LoadBalancerClient` under the hood. Additionally,
`spring-cloud-starter-netflix-ribbon` is already in maintenance mode, so we do not recommend
adding it to new projects.
If you have both `spring-cloud-starter-loadbalancer` and `spring-cloud-starter-netflix-ribbon`
in your classpath, Ribbon is used by default. To switch to Spring Cloud LoadBalancer,
set the `spring.cloud.loadbalancer.ribbon.enabled` property to `false`.

==== Retrying Failed Requests

A load-balanced `RestTemplate` can be configured to retry failed requests.
By default, this logic is disabled.
You can enable it by adding link:https://github.com/spring-projects/spring-retry[Spring Retry] to your application's classpath.
The load-balanced `RestTemplate` honors some of the Ribbon configuration values related to retrying failed requests.
You can use `client.ribbon.MaxAutoRetries`, `client.ribbon.MaxAutoRetriesNextServer`, and `client.ribbon.OkToRetryOnAllOperations` properties.
If you would like to disable the retry logic with Spring Retry on the classpath, you can set `spring.cloud.loadbalancer.retry.enabled=false`.
See the https://github.com/Netflix/ribbon/wiki/Getting-Started#the-properties-file-sample-clientproperties[Ribbon documentation] for a description of what these properties do.

If you would like to implement a `BackOffPolicy` in your retries, you need to create a bean of type `LoadBalancedRetryFactory` and override the `createBackOffPolicy` method:

Expand All @@ -478,8 +460,6 @@ public class MyConfiguration {
----
====

NOTE: `client` in the preceding examples should be replaced with your Ribbon client's name.

If you want to add one or more `RetryListener` implementations to your retry functionality, you need to
create a bean of type `LoadBalancedRetryListenerFactory` and return the `RetryListener` array
you would like to use for a given service, as the following example shows:
Expand Down Expand Up @@ -649,16 +629,9 @@ public class MyClass {
The URI needs to use a virtual host name (that is, a service name, not a host name).
The `ReactorLoadBalancer` is used to create a full physical address.

NOTE: By default, if you have `spring-cloud-netflix-ribbon` in your classpath, <<load-balancer-exchange-filter-function,`LoadBalancerExchangeFilterFunction`>>
is used to maintain backward compatibility. To use
`ReactorLoadBalancerExchangeFilterFunction`, set the `spring.cloud.loadbalancer.ribbon.enabled` property
to `false`.

[[load-balancer-exchange-filter-function]]
==== Spring WebFlux `WebClient` with a Non-reactive Load Balancer Client

If you you do not have <<spring-cloud-loadbalancer-starter, Spring Cloud LoadBalancer starter>> in your project
but you do have spring-cloud-starter-netflix-ribbon, you can still use `WebClient` with `LoadBalancerClient`.
If `spring-webflux` is on the classpath, `LoadBalancerExchangeFilterFunction`
is auto-configured. Note, however, that this
uses a non-reactive client under the hood.
Expand Down Expand Up @@ -1004,9 +977,6 @@ NOTE: Spring Cloud LoadBalancer starter includes
https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-caching.html[Spring Boot Caching]
and https://github.com/stoyanr[Evictor].

WARNING: If you have both Ribbon and Spring Cloud LoadBalancer int the classpath, in order to maintain backward compatibility, Ribbon-based implementations will be used by default.
In order to switch to using Spring Cloud LoadBalancer under the hood, make sure you set the property `spring.cloud.loadbalancer.ribbon.enabled` to `false`.

[[custom-loadbalancer-configuration]]
=== Passing Your Own Spring Cloud LoadBalancer Configuration

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import org.springframework.web.client.AsyncRestTemplate;

/**
* Auto-configuration for Ribbon (client-side load balancing).
* Auto-configuration for blocking client-side load balancing.
*
* @author Rob Worsnop
*/
Expand All @@ -49,13 +49,10 @@ static class AsyncRestTemplateCustomizerConfig {
@Bean
public SmartInitializingSingleton loadBalancedAsyncRestTemplateInitializer(
final List<AsyncRestTemplateCustomizer> customizers) {
return new SmartInitializingSingleton() {
@Override
public void afterSingletonsInstantiated() {
for (AsyncRestTemplate restTemplate : AsyncRestTemplateCustomizerConfig.this.restTemplates) {
for (AsyncRestTemplateCustomizer customizer : customizers) {
customizer.customize(restTemplate);
}
return () -> {
for (AsyncRestTemplate restTemplate : AsyncRestTemplateCustomizerConfig.this.restTemplates) {
for (AsyncRestTemplateCustomizer customizer : customizers) {
customizer.customize(restTemplate);
}
}
};
Expand All @@ -75,14 +72,11 @@ public AsyncLoadBalancerInterceptor asyncLoadBalancerInterceptor(
@Bean
public AsyncRestTemplateCustomizer asyncRestTemplateCustomizer(
final AsyncLoadBalancerInterceptor loadBalancerInterceptor) {
return new AsyncRestTemplateCustomizer() {
@Override
public void customize(AsyncRestTemplate restTemplate) {
List<AsyncClientHttpRequestInterceptor> list = new ArrayList<>(
restTemplate.getInterceptors());
list.add(loadBalancerInterceptor);
restTemplate.setInterceptors(list);
}
return restTemplate -> {
List<AsyncClientHttpRequestInterceptor> list = new ArrayList<>(
restTemplate.getInterceptors());
list.add(loadBalancerInterceptor);
restTemplate.setInterceptors(list);
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import org.springframework.web.client.RestTemplate;

/**
* Auto-configuration for Ribbon (client-side load balancing).
* Auto-configuration for blocking (client-side load balancing).
*
* @author Spencer Gibb
* @author Dave Syer
Expand Down Expand Up @@ -79,7 +79,7 @@ public LoadBalancerRequestFactory loadBalancerRequestFactory(
static class LoadBalancerInterceptorConfig {

@Bean
public LoadBalancerInterceptor ribbonInterceptor(
public LoadBalancerInterceptor loadBalancerInterceptor(
LoadBalancerClient loadBalancerClient,
LoadBalancerRequestFactory requestFactory) {
return new LoadBalancerInterceptor(loadBalancerClient, requestFactory);
Expand Down Expand Up @@ -124,7 +124,7 @@ public static class RetryInterceptorAutoConfiguration {

@Bean
@ConditionalOnMissingBean
public RetryLoadBalancerInterceptor ribbonInterceptor(
public RetryLoadBalancerInterceptor loadBalancerInterceptor(
LoadBalancerClient loadBalancerClient,
LoadBalancerRetryProperties properties,
LoadBalancerRequestFactory requestFactory,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@

import org.springframework.beans.factory.ObjectProvider;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.AnyNestedCondition;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.context.ApplicationContext;
Expand Down Expand Up @@ -57,7 +55,6 @@ public LoadBalancerWebClientBuilderBeanPostProcessor loadBalancerWebClientBuilde
}

@Configuration(proxyBeanMethods = false)
@Conditional(OnNoRibbonDefaultCondition.class)
@ConditionalOnBean(ReactiveLoadBalancer.Factory.class)
protected static class ReactorDeferringLoadBalancerFilterConfig {

Expand All @@ -71,22 +68,6 @@ DeferringLoadBalancerExchangeFilterFunction<ReactorLoadBalancerExchangeFilterFun

}

@Configuration(proxyBeanMethods = false)
@ConditionalOnBean(LoadBalancerClient.class)
@AutoConfigureAfter(ReactorDeferringLoadBalancerFilterConfig.class)
@Deprecated
protected static class ReactiveLoadBalancerConfig {

@Bean
@ConditionalOnMissingBean
DeferringLoadBalancerExchangeFilterFunction<LoadBalancerExchangeFilterFunction> deferringLoadBalancerExchangeFilterFunction(
ObjectProvider<LoadBalancerExchangeFilterFunction> exchangeFilterFunctionProvider) {
return new DeferringLoadBalancerExchangeFilterFunction<>(
exchangeFilterFunctionProvider);
}

}

static final class OnAnyLoadBalancerImplementationPresentCondition
extends AnyNestedCondition {

Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Loading