sentinel 使用说明


sentinel 使用说明

        

             

                                 

相关依赖

         

        
        
            com.alibaba.cloud
            spring-cloud-starter-alibaba-sentinel
        

        
        
            com.alibaba.csp
            sentinel-apache-dubbo-adapter
        

        
        
            com.alibaba.cloud
            spring-cloud-alibaba-sentinel-datasource
        

        
        
            com.alibaba.cloud
            spring-cloud-alibaba-sentinel-gateway
        

             

                

                                 

自动配置类

   

spring-cloud-starter-alibaba-sentinel/spring.factories

               sentinel 使用说明_第1张图片

org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.alibaba.cloud.sentinel.SentinelWebAutoConfiguration,\
com.alibaba.cloud.sentinel.SentinelWebFluxAutoConfiguration,\
com.alibaba.cloud.sentinel.endpoint.SentinelEndpointAutoConfiguration,\
com.alibaba.cloud.sentinel.custom.SentinelAutoConfiguration,\
com.alibaba.cloud.sentinel.feign.SentinelFeignAutoConfiguration

org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker=\
com.alibaba.cloud.sentinel.custom.SentinelCircuitBreakerConfiguration

             

SentinelAutoConfiguration

@Configuration(
    proxyBeanMethods = false
)
@ConditionalOnProperty(
    name = {"spring.cloud.sentinel.enabled"},
    matchIfMissing = true
)
@EnableConfigurationProperties({SentinelProperties.class})  //从配置文件中读取数据,装配SentinelProperties类
public class SentinelAutoConfiguration {
    @Value("${project.name:${spring.application.name:}}")
    private String projectName;
    @Autowired
    private SentinelProperties properties;

    public SentinelAutoConfiguration() {
    }

    @PostConstruct
    private void init() {   //初始化属性配置
        if (StringUtils.isEmpty(System.getProperty("csp.sentinel.log.dir")) && StringUtils.hasText(this.properties.getLog().getDir())) {
            System.setProperty("csp.sentinel.log.dir", this.properties.getLog().getDir());
        }

        if (StringUtils.isEmpty(System.getProperty("csp.sentinel.log.use.pid")) && this.properties.getLog().isSwitchPid()) {
            System.setProperty("csp.sentinel.log.use.pid", String.valueOf(this.properties.getLog().isSwitchPid()));
        }

        if (StringUtils.isEmpty(System.getProperty("csp.sentinel.app.name")) && StringUtils.hasText(this.projectName)) {
            System.setProperty("csp.sentinel.app.name", this.projectName);
        }

        if (StringUtils.isEmpty(System.getProperty("csp.sentinel.api.port")) && StringUtils.hasText(this.properties.getTransport().getPort())) {
            System.setProperty("csp.sentinel.api.port", this.properties.getTransport().getPort());
        }

        if (StringUtils.isEmpty(System.getProperty("csp.sentinel.dashboard.server")) && StringUtils.hasText(this.properties.getTransport().getDashboard())) {
            System.setProperty("csp.sentinel.dashboard.server", this.properties.getTransport().getDashboard());
        }

        if (StringUtils.isEmpty(System.getProperty("csp.sentinel.heartbeat.interval.ms")) && StringUtils.hasText(this.properties.getTransport().getHeartbeatIntervalMs())) {
            System.setProperty("csp.sentinel.heartbeat.interval.ms", this.properties.getTransport().getHeartbeatIntervalMs());
        }

        if (StringUtils.isEmpty(System.getProperty("csp.sentinel.heartbeat.client.ip")) && StringUtils.hasText(this.properties.getTransport().getClientIp())) {
            System.setProperty("csp.sentinel.heartbeat.client.ip", this.properties.getTransport().getClientIp());
        }

        if (StringUtils.isEmpty(System.getProperty("csp.sentinel.charset")) && StringUtils.hasText(this.properties.getMetric().getCharset())) {
            System.setProperty("csp.sentinel.charset", this.properties.getMetric().getCharset());
        }

        if (StringUtils.isEmpty(System.getProperty("csp.sentinel.metric.file.single.size")) && StringUtils.hasText(this.properties.getMetric().getFileSingleSize())) {
            System.setProperty("csp.sentinel.metric.file.single.size", this.properties.getMetric().getFileSingleSize());
        }

        if (StringUtils.isEmpty(System.getProperty("csp.sentinel.metric.file.total.count")) && StringUtils.hasTe

你可能感兴趣的:(spring,cloud,alibaba,sentinel,sentinel)