From d15c6680a27e96404b5fb526d3528b5cc1f66831 Mon Sep 17 00:00:00 2001 From: jizhuozhi Date: Fri, 10 Nov 2023 01:36:44 +0800 Subject: [PATCH] feat(lb): deterministic subsetting algorithm to limit the number of instances --- .../annotation/LoadBalancerClientConfiguration.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/spring-cloud-loadbalancer/src/main/java/org/springframework/cloud/loadbalancer/annotation/LoadBalancerClientConfiguration.java b/spring-cloud-loadbalancer/src/main/java/org/springframework/cloud/loadbalancer/annotation/LoadBalancerClientConfiguration.java index 415112954..8e7a56834 100644 --- a/spring-cloud-loadbalancer/src/main/java/org/springframework/cloud/loadbalancer/annotation/LoadBalancerClientConfiguration.java +++ b/spring-cloud-loadbalancer/src/main/java/org/springframework/cloud/loadbalancer/annotation/LoadBalancerClientConfiguration.java @@ -217,6 +217,15 @@ public ServiceInstanceListSupplier weightedServiceInstanceListSupplier(Configura .build(context); } + @Bean + @ConditionalOnBean(DiscoveryClient.class) + @ConditionalOnMissingBean + @Conditional(SubsetConfigurationCondition.class) + public ServiceInstanceListSupplier subsetServiceInstanceListSupplier(ConfigurableApplicationContext context) { + return ServiceInstanceListSupplier.builder().withBlockingDiscoveryClient().withSubset().withCaching() + .build(context); + } + } @Configuration(proxyBeanMethods = false)