Allow disabling load-balancing with property. (#940)

This commit is contained in:
Olga Maciaszek-Sharma
2021-04-01 16:42:34 +02:00
committed by GitHub
parent 8f8059d5af
commit ac7e8f922b
4 changed files with 11 additions and 0 deletions

View File

@@ -30,6 +30,7 @@
|spring.cloud.loadbalancer.cache.enabled | `true` | Enables Spring Cloud LoadBalancer caching mechanism.
|spring.cloud.loadbalancer.cache.ttl | `35s` | Time To Live - time counted from writing of the record, after which cache entries are expired, expressed as a {@link Duration}. The property {@link String} has to be in keeping with the appropriate syntax as specified in Spring Boot <code>StringToDurationConverter</code>. @see <a href= "https://github.com/spring-projects/spring-boot/blob/master/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/convert/StringToDurationConverter.java">StringToDurationConverter.java</a>
|spring.cloud.loadbalancer.configurations | `default` | Enables a predefined LoadBalancer configuration.
|spring.cloud.loadbalancer.enabled | `true` | Enables Spring Cloud LoadBalancer.
|spring.cloud.loadbalancer.health-check.initial-delay | `0` | Initial delay value for the HealthCheck scheduler.
|spring.cloud.loadbalancer.health-check.interval | `25s` | Interval for rerunning the HealthCheck scheduler.
|spring.cloud.loadbalancer.health-check.path | |

View File

@@ -845,6 +845,8 @@ have been provided for it. In order to get instances to select from reactive `Se
is used. Currently we support a service-discovery-based implementation of `ServiceInstanceListSupplier`
that retrieves available instances from Service Discovery using a <<discovery-client, Discovery Client>> available in the classpath.
TIP: It is possible to disable Spring Cloud LoadBalancer by setting the value of `spring.cloud.loadbalancer.enabled` to `false`.
=== Switching between the load-balancing algorithms
The `ReactiveLoadBalancer` implementation that is used by default is `RoundRobinLoadBalancer`. To switch to a different implementation, either for selected services or all of them, you can use the <<custom-loadbalancer-configuration, custom LoadBalancer configurations mechanism>>.

View File

@@ -22,6 +22,7 @@ import java.util.List;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.client.loadbalancer.LoadBalancerProperties;
import org.springframework.cloud.client.loadbalancer.reactive.LoadBalancerBeanPostProcessorAutoConfiguration;
@@ -42,6 +43,7 @@ import org.springframework.core.env.Environment;
@EnableConfigurationProperties(LoadBalancerProperties.class)
@AutoConfigureBefore({ ReactorLoadBalancerClientAutoConfiguration.class,
LoadBalancerBeanPostProcessorAutoConfiguration.class })
@ConditionalOnProperty(value = "spring.cloud.loadbalancer.enabled", havingValue = "true", matchIfMissing = true)
public class LoadBalancerAutoConfiguration {
private final ObjectProvider<List<LoadBalancerClientSpecification>> configurations;

View File

@@ -33,6 +33,12 @@
"name": "spring.cloud.loadbalancer.configurations",
"description": "Enables a predefined LoadBalancer configuration.",
"type": "java.lang.String"
},
{
"defaultValue": "true",
"name": "spring.cloud.loadbalancer.enabled",
"description": "Enables Spring Cloud LoadBalancer.",
"type": "java.lang.Boolean"
}
]
}