diff --git a/CHANGELOG.md b/CHANGELOG.md index 5f303ea69..759c15001 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,3 +15,4 @@ - [refactor:refactor stat module.](https://github.com/Tencent/spring-cloud-tencent/pull/876) - [fix:fix NPE.](https://github.com/Tencent/spring-cloud-tencent/pull/883) - [refactor:optimize sct-all.](https://github.com/Tencent/spring-cloud-tencent/pull/887) +- [fix:fix instance circuit breaker not working bug.](https://github.com/Tencent/spring-cloud-tencent/pull/891) diff --git a/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/loadbalancer/PolarisLoadBalancerClientConfiguration.java b/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/loadbalancer/PolarisLoadBalancerClientConfiguration.java index 64f8b8798..3d9bf1a40 100644 --- a/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/loadbalancer/PolarisLoadBalancerClientConfiguration.java +++ b/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/loadbalancer/PolarisLoadBalancerClientConfiguration.java @@ -20,15 +20,22 @@ package com.tencent.cloud.polaris.loadbalancer; import com.tencent.cloud.polaris.context.ConditionalOnPolarisEnabled; import com.tencent.polaris.router.api.core.RouterAPI; +import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; 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; import org.springframework.cloud.client.ServiceInstance; +import org.springframework.cloud.client.discovery.DiscoveryClient; +import org.springframework.cloud.client.discovery.ReactiveDiscoveryClient; import org.springframework.cloud.loadbalancer.core.ReactorLoadBalancer; import org.springframework.cloud.loadbalancer.core.ServiceInstanceListSupplier; import org.springframework.cloud.loadbalancer.support.LoadBalancerClientFactory; +import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.core.annotation.Order; import org.springframework.core.env.Environment; /** @@ -41,6 +48,11 @@ import org.springframework.core.env.Environment; @ConditionalOnDiscoveryEnabled public class PolarisLoadBalancerClientConfiguration { + /** + * Order of reactive discovery service instance supplier. + */ + private static final int REACTIVE_SERVICE_INSTANCE_SUPPLIER_ORDER = 193827465; + private final static String STRATEGY_WEIGHT = "polarisWeighted"; @Bean @@ -52,4 +64,35 @@ public class PolarisLoadBalancerClientConfiguration { return new PolarisLoadBalancer(name, loadBalancerClientFactory.getLazyProvider(name, ServiceInstanceListSupplier.class), routerAPI); } + + @Configuration(proxyBeanMethods = false) + @ConditionalOnReactiveDiscoveryEnabled + @Order(REACTIVE_SERVICE_INSTANCE_SUPPLIER_ORDER) + protected static class PolarisReactiveSupportConfiguration { + + @Bean + @ConditionalOnMissingBean + @ConditionalOnBean(ReactiveDiscoveryClient.class) + public ServiceInstanceListSupplier polarisRouterDiscoveryClientServiceInstanceListSupplier( + ConfigurableApplicationContext context) { + return new PolarisServiceInstanceListSupplier( + ServiceInstanceListSupplier.builder().withDiscoveryClient().build(context)); + } + + } + + @Configuration(proxyBeanMethods = false) + @ConditionalOnBlockingDiscoveryEnabled + @Order(REACTIVE_SERVICE_INSTANCE_SUPPLIER_ORDER + 1) + protected static class PolarisBlockingSupportConfiguration { + + @Bean + @ConditionalOnMissingBean + @ConditionalOnBean(DiscoveryClient.class) + public ServiceInstanceListSupplier polarisRouterDiscoveryClientServiceInstanceListSupplier( + ConfigurableApplicationContext context) { + return new PolarisServiceInstanceListSupplier( + ServiceInstanceListSupplier.builder().withBlockingDiscoveryClient().build(context)); + } + } } diff --git a/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/loadbalancer/PolarisServiceInstanceListSupplier.java b/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/loadbalancer/PolarisServiceInstanceListSupplier.java new file mode 100644 index 000000000..dfc250dda --- /dev/null +++ b/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/loadbalancer/PolarisServiceInstanceListSupplier.java @@ -0,0 +1,49 @@ +/* + * Tencent is pleased to support the open source community by making Spring Cloud Tencent available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * Licensed under the BSD 3-Clause License (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://opensource.org/licenses/BSD-3-Clause + * + * Unless required by applicable law or agreed to in writing, software distributed + * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + * CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ + +package com.tencent.cloud.polaris.loadbalancer; + +import java.util.List; + +import reactor.core.publisher.Flux; + +import org.springframework.cloud.client.ServiceInstance; +import org.springframework.cloud.client.loadbalancer.Request; +import org.springframework.cloud.loadbalancer.core.DelegatingServiceInstanceListSupplier; +import org.springframework.cloud.loadbalancer.core.ServiceInstanceListSupplier; + +/** + * Service instance list supplier of Polaris. + * + * @author Haotian Zhang + */ +public class PolarisServiceInstanceListSupplier extends DelegatingServiceInstanceListSupplier { + + public PolarisServiceInstanceListSupplier(ServiceInstanceListSupplier delegate) { + super(delegate); + } + + @Override + public Flux> get() { + return getDelegate().get(); + } + + @Override + public Flux> get(Request request) { + return super.get(request); + } +} diff --git a/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/registry/PolarisServiceRegistry.java b/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/registry/PolarisServiceRegistry.java index 22fa2f93d..8a4177026 100644 --- a/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/registry/PolarisServiceRegistry.java +++ b/spring-cloud-starter-tencent-polaris-discovery/src/main/java/com/tencent/cloud/polaris/registry/PolarisServiceRegistry.java @@ -41,6 +41,7 @@ import com.tencent.polaris.api.rpc.InstanceRegisterRequest; import com.tencent.polaris.api.rpc.InstanceRegisterResponse; import com.tencent.polaris.api.rpc.InstancesResponse; import com.tencent.polaris.client.util.NamedThreadFactory; +import com.tencent.polaris.factory.config.provider.ServiceConfigImpl; import org.apache.commons.lang.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -145,6 +146,11 @@ public class PolarisServiceRegistry implements ServiceRegistry1.10.0-2021.0.6-SNAPSHOT - 1.11.0 + 1.11.1-SNAPSHOT 31.0.1-jre 1.2.11 4.5.1