parent
b46d6ec2db
commit
b956a31226
@ -0,0 +1,35 @@
|
|||||||
|
package com.tencent.cloud.polaris.circuitbreaker;
|
||||||
|
|
||||||
|
import com.tencent.cloud.polaris.context.PolarisContextAutoConfiguration;
|
||||||
|
import com.tencent.polaris.api.core.ConsumerAPI;
|
||||||
|
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.ConditionalOnProperty;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author : wh
|
||||||
|
* @date : 2022/6/21 21:34
|
||||||
|
* @description:
|
||||||
|
*/
|
||||||
|
@ConditionalOnProperty(value = "spring.cloud.polaris.circuitbreaker.enabled",
|
||||||
|
havingValue = "true", matchIfMissing = true)
|
||||||
|
@Configuration(proxyBeanMethods = false)
|
||||||
|
@AutoConfigureAfter(PolarisContextAutoConfiguration.class)
|
||||||
|
public class PolarisRestTemplateAutoConfiguration {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@ConditionalOnBean(RestTemplate.class)
|
||||||
|
public PolarisRestTemplateResponseErrorHandler polarisRestTemplateResponseErrorHandler(ConsumerAPI consumerAPI, @Autowired(required = false) PolarisResponseErrorHandler polarisResponseErrorHandler) {
|
||||||
|
return new PolarisRestTemplateResponseErrorHandler(consumerAPI, polarisResponseErrorHandler);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@ConditionalOnBean(RestTemplate.class)
|
||||||
|
public PolarisRestTemplateBeanPostProcessor polarisRestTemplateBeanPostProcessor(PolarisRestTemplateResponseErrorHandler restTemplateResponseErrorHandler) {
|
||||||
|
return new PolarisRestTemplateBeanPostProcessor(restTemplateResponseErrorHandler);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,39 @@
|
|||||||
|
package com.tencent.cloud.polaris.circuitbreaker;
|
||||||
|
|
||||||
|
import org.springframework.beans.BeansException;
|
||||||
|
import org.springframework.beans.factory.SmartInitializingSingleton;
|
||||||
|
import org.springframework.context.ApplicationContext;
|
||||||
|
import org.springframework.context.ApplicationContextAware;
|
||||||
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author : wh
|
||||||
|
* @date : 2022/6/21 21:20
|
||||||
|
* @description:
|
||||||
|
*/
|
||||||
|
public class PolarisRestTemplateBeanPostProcessor implements ApplicationContextAware, SmartInitializingSingleton {
|
||||||
|
|
||||||
|
private ApplicationContext applicationContext;
|
||||||
|
|
||||||
|
private final PolarisRestTemplateResponseErrorHandler polarisRestTemplateResponseErrorHandler;
|
||||||
|
|
||||||
|
public PolarisRestTemplateBeanPostProcessor(PolarisRestTemplateResponseErrorHandler polarisRestTemplateResponseErrorHandler) {
|
||||||
|
this.polarisRestTemplateResponseErrorHandler = polarisRestTemplateResponseErrorHandler;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void afterSingletonsInstantiated() {
|
||||||
|
RestTemplate restTemplate = this.applicationContext.getBean(RestTemplate.class);
|
||||||
|
if (Objects.nonNull(restTemplate)) {
|
||||||
|
restTemplate.setErrorHandler(polarisRestTemplateResponseErrorHandler);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
||||||
|
this.applicationContext = applicationContext;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,6 @@
|
|||||||
org.springframework.cloud.bootstrap.BootstrapConfiguration=\
|
org.springframework.cloud.bootstrap.BootstrapConfiguration=\
|
||||||
com.tencent.cloud.polaris.circuitbreaker.PolarisCircuitBreakerBootstrapConfiguration
|
com.tencent.cloud.polaris.circuitbreaker.PolarisCircuitBreakerBootstrapConfiguration
|
||||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||||
com.tencent.cloud.polaris.circuitbreaker.PolarisFeignClientAutoConfiguration
|
com.tencent.cloud.polaris.circuitbreaker.PolarisFeignClientAutoConfiguration,\
|
||||||
|
com.tencent.cloud.polaris.circuitbreaker.PolarisRestTemplateAutoConfiguration
|
||||||
|
|
||||||
|
Loading…
Reference in new issue