From f7576abf2e6134458d63363b1160b8c3aca1b804 Mon Sep 17 00:00:00 2001 From: lepdou Date: Wed, 15 Jun 2022 14:52:47 +0800 Subject: [PATCH] optimize router: remove strong dependency on spring.cloud.loadbalancer.configurations properties (#234) --- .../router/config/LoadBalancerConfiguration.java | 3 --- .../src/main/resources/bootstrap.yml | 2 -- .../loadbalancer/PolarisLoadBalancer.java | 16 ++++++++-------- 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/spring-cloud-starter-tencent-polaris-router/src/main/java/com/tencent/cloud/polaris/router/config/LoadBalancerConfiguration.java b/spring-cloud-starter-tencent-polaris-router/src/main/java/com/tencent/cloud/polaris/router/config/LoadBalancerConfiguration.java index a77a8588c..6d02df9be 100644 --- a/spring-cloud-starter-tencent-polaris-router/src/main/java/com/tencent/cloud/polaris/router/config/LoadBalancerConfiguration.java +++ b/spring-cloud-starter-tencent-polaris-router/src/main/java/com/tencent/cloud/polaris/router/config/LoadBalancerConfiguration.java @@ -22,7 +22,6 @@ import com.tencent.cloud.polaris.router.PolarisRouterServiceInstanceListSupplier import com.tencent.polaris.router.api.core.RouterAPI; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.cloud.client.ConditionalOnBlockingDiscoveryEnabled; import org.springframework.cloud.client.ConditionalOnDiscoveryEnabled; import org.springframework.cloud.client.ConditionalOnReactiveDiscoveryEnabled; @@ -54,7 +53,6 @@ public class LoadBalancerConfiguration { @Bean @ConditionalOnBean(ReactiveDiscoveryClient.class) - @ConditionalOnProperty(value = "spring.cloud.loadbalancer.configurations", havingValue = "polaris") public ServiceInstanceListSupplier polarisRouterDiscoveryClientServiceInstanceListSupplier( ConfigurableApplicationContext context, RouterAPI routerAPI, @@ -78,7 +76,6 @@ public class LoadBalancerConfiguration { @Bean @ConditionalOnBean(DiscoveryClient.class) - @ConditionalOnProperty(value = "spring.cloud.loadbalancer.configurations", havingValue = "polaris") public ServiceInstanceListSupplier polarisRouterDiscoveryClientServiceInstanceListSupplier( ConfigurableApplicationContext context, RouterAPI routerAPI, diff --git a/spring-cloud-tencent-examples/polaris-router-example/router-caller-service/src/main/resources/bootstrap.yml b/spring-cloud-tencent-examples/polaris-router-example/router-caller-service/src/main/resources/bootstrap.yml index 6d95219fc..e8f793330 100644 --- a/spring-cloud-tencent-examples/polaris-router-example/router-caller-service/src/main/resources/bootstrap.yml +++ b/spring-cloud-tencent-examples/polaris-router-example/router-caller-service/src/main/resources/bootstrap.yml @@ -8,8 +8,6 @@ spring: metadata: content: k1: v1 - loadbalancer: - configurations: polaris polaris: address: grpc://183.47.111.80:8091 namespace: default diff --git a/spring-cloud-tencent-polaris-loadbalancer/src/main/java/com/tencent/cloud/polaris/loadbalancer/PolarisLoadBalancer.java b/spring-cloud-tencent-polaris-loadbalancer/src/main/java/com/tencent/cloud/polaris/loadbalancer/PolarisLoadBalancer.java index cfed4fb8c..737b465f3 100644 --- a/spring-cloud-tencent-polaris-loadbalancer/src/main/java/com/tencent/cloud/polaris/loadbalancer/PolarisLoadBalancer.java +++ b/spring-cloud-tencent-polaris-loadbalancer/src/main/java/com/tencent/cloud/polaris/loadbalancer/PolarisLoadBalancer.java @@ -72,14 +72,6 @@ public class PolarisLoadBalancer extends RoundRobinLoadBalancer { this.routerAPI = routerAPI; } - private static ServiceInstances convertToPolarisServiceInstances(List serviceInstances) { - ServiceKey serviceKey = new ServiceKey(MetadataContext.LOCAL_NAMESPACE, serviceInstances.get(0).getServiceId()); - List polarisInstances = serviceInstances.stream() - .map(serviceInstance -> ((PolarisServiceInstance) serviceInstance).getPolarisInstance()) - .collect(Collectors.toList()); - return new DefaultServiceInstances(serviceKey, polarisInstances); - } - @Override public Mono> choose(Request request) { if (!loadBalancerProperties.getEnabled()) { @@ -111,4 +103,12 @@ public class PolarisLoadBalancer extends RoundRobinLoadBalancer { } } + private static ServiceInstances convertToPolarisServiceInstances(List serviceInstances) { + ServiceKey serviceKey = new ServiceKey(MetadataContext.LOCAL_NAMESPACE, serviceInstances.get(0).getServiceId()); + List polarisInstances = serviceInstances.stream() + .map(serviceInstance -> ((PolarisServiceInstance) serviceInstance).getPolarisInstance()) + .collect(Collectors.toList()); + return new DefaultServiceInstances(serviceKey, polarisInstances); + } + }