fix:fix circuit breaker bean load order bug when using Nacos discovery.

pull/1080/head
Haotian Zhang 1 year ago
parent 3828b39c15
commit fe88e4af73

@ -15,3 +15,4 @@
- build(deps): bump guava in /spring-cloud-tencent-dependencies
- fix:fix reporting bug when port is -1.
- fix:update guava version.
- fix:fix circuit breaker bean load order bug when using Nacos discovery.

@ -36,7 +36,6 @@ import com.tencent.cloud.rpc.enhancement.config.RpcEnhancementReporterProperties
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
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.circuitbreaker.CircuitBreakerFactory;
@ -98,7 +97,6 @@ public class PolarisCircuitBreakerAutoConfiguration {
}
@Bean
@ConditionalOnBean(RpcEnhancementReporterProperties.class)
@ConditionalOnMissingBean(CircuitBreakerConfigModifier.class)
public CircuitBreakerConfigModifier circuitBreakerConfigModifier(RpcEnhancementReporterProperties properties) {
return new CircuitBreakerConfigModifier(properties);

@ -30,7 +30,6 @@ import com.tencent.cloud.rpc.enhancement.config.RpcEnhancementReporterProperties
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
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.circuitbreaker.Customizer;
@ -76,7 +75,6 @@ public class ReactivePolarisCircuitBreakerAutoConfiguration {
}
@Bean
@ConditionalOnBean(RpcEnhancementReporterProperties.class)
@ConditionalOnMissingBean(CircuitBreakerConfigModifier.class)
public CircuitBreakerConfigModifier reactiveCircuitBreakerConfigModifier(RpcEnhancementReporterProperties properties) {
return new CircuitBreakerConfigModifier(properties);

@ -23,6 +23,7 @@ import com.tencent.cloud.polaris.circuitbreaker.feign.PolarisCircuitBreakerNameR
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.cloud.client.circuitbreaker.CircuitBreakerFactory;
import org.springframework.context.annotation.Bean;
@ -36,7 +37,7 @@ import org.springframework.context.annotation.Primary;
*/
@Configuration(proxyBeanMethods = false)
@ConditionalOnClass({Targeter.class})
@ConditionalOnProperty(value = "feign.circuitbreaker.enabled", havingValue = "true")
@ConditionalOnProperty(value = "feign.hystrix.enabled", havingValue = "true")
@AutoConfigureBefore(FeignAutoConfiguration.class)
@ConditionalOnPolarisCircuitBreakerEnabled
public class PolarisFeignCircuitBreakerTargeterAutoConfiguration {
@ -44,6 +45,7 @@ public class PolarisFeignCircuitBreakerTargeterAutoConfiguration {
@Bean
@Primary
@ConditionalOnBean(CircuitBreakerFactory.class)
@ConditionalOnMissingBean(Targeter.class)
public Targeter polarisFeignCircuitBreakerTargeter(CircuitBreakerFactory circuitBreakerFactory, PolarisCircuitBreakerNameResolver circuitBreakerNameResolver) {
return new PolarisFeignCircuitBreakerTargeter(circuitBreakerFactory, circuitBreakerNameResolver);
}

@ -5,4 +5,5 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.tencent.cloud.polaris.circuitbreaker.config.PolarisCircuitBreakerFeignClientAutoConfiguration,\
org.springframework.cloud.openfeign.PolarisFeignCircuitBreakerTargeterAutoConfiguration
org.springframework.cloud.bootstrap.BootstrapConfiguration=\
com.tencent.cloud.polaris.circuitbreaker.config.PolarisCircuitBreakerBootstrapConfiguration
com.tencent.cloud.polaris.circuitbreaker.config.PolarisCircuitBreakerBootstrapConfiguration,\
org.springframework.cloud.openfeign.PolarisFeignCircuitBreakerTargeterAutoConfiguration

@ -23,6 +23,7 @@ import java.util.List;
import com.netflix.client.config.IClientConfig;
import com.netflix.loadbalancer.AbstractLoadBalancerRule;
import com.tencent.cloud.common.util.BeanFactoryUtils;
import com.tencent.cloud.polaris.context.PolarisSDKContextManager;
import com.tencent.cloud.polaris.loadbalancer.config.PolarisLoadBalancerProperties;
import com.tencent.cloud.polaris.router.PolarisLoadBalancerCompositeRule;
import com.tencent.cloud.polaris.router.spi.RouterRequestInterceptor;
@ -47,7 +48,8 @@ public class PolarisLoadBalancerCompositeRuleBeanPostProcessor implements BeanPo
@Override
public Object postProcessBeforeInitialization(@NonNull Object bean, @NonNull String beanName) throws BeansException {
if (bean instanceof AbstractLoadBalancerRule) {
RouterAPI routerAPI = beanFactory.getBean(RouterAPI.class);
PolarisSDKContextManager polarisSDKContextManager = beanFactory.getBean(PolarisSDKContextManager.class);
RouterAPI routerAPI = polarisSDKContextManager.getRouterAPI();
PolarisLoadBalancerProperties polarisLoadBalancerProperties = beanFactory.getBean(PolarisLoadBalancerProperties.class);
IClientConfig iClientConfig = beanFactory.getBean(IClientConfig.class);
List<RouterRequestInterceptor> requestInterceptors = BeanFactoryUtils.getBeans(beanFactory, RouterRequestInterceptor.class);

@ -18,16 +18,22 @@
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- <dependency>-->
<!-- <groupId>com.tencent.cloud</groupId>-->
<!-- <artifactId>spring-cloud-starter-tencent-polaris-circuitbreaker</artifactId>-->
<!-- </dependency>-->
<dependency>
<groupId>com.tencent.cloud</groupId>
<artifactId>spring-cloud-starter-tencent-polaris-router</artifactId>
</dependency>
<dependency>
<groupId>com.tencent.cloud</groupId>
<artifactId>spring-cloud-starter-tencent-discovery-adapter-plugin</artifactId>
</dependency>
<dependency>
<groupId>com.tencent.cloud</groupId>
<artifactId>spring-cloud-starter-tencent-polaris-circuitbreaker</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>

@ -188,6 +188,7 @@ public class RpcEnhancementAutoConfiguration {
public PolarisLoadBalancerRequestTransformer polarisLoadBalancerRequestTransformer() {
return new PolarisLoadBalancerRequestTransformer();
}
}
/**

Loading…
Cancel
Save