springcloud 集成Sentinel 1.8持久化到zookeeper

1、客户端pom引入

  因sentinel-datasource-zookeeper 自带的zookeeper版本过高 排除 添加指定的版本的zookeeper版本

 <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
            <version>2.2.4.RELEASE</version>
            <exclusions>
                <exclusion>
                    <groupId>com.alibaba</groupId>
                    <artifactId>fastjson</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
<dependency>
            <groupId>org.apache.zookeeper</groupId>
            <artifactId>zookeeper</artifactId>
            <version>3.4.11</version>
            <exclusions>
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-log4j12</artifactId>
                </exclusion>
                <exclusion>
                    <artifactId>slf4j-api</artifactId>
                    <groupId>org.slf4j</groupId>
                </exclusion>
                <exclusion>
                    <groupId>log4j</groupId>
                    <artifactId>log4j</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>com.alibaba.csp</groupId>
            <artifactId>sentinel-datasource-zookeeper</artifactId>
            <version>1.8.0</version>
            <exclusions>
                <exclusion>
                    <artifactId>zookeeper</artifactId>
                    <groupId>org.apache.zookeeper</groupId>
                </exclusion>
            </exclusions>
        </dependency>

2、yaml文件修改

spring:
  cloud:
    sentinel:
      port: 8719
      eager: true
      transport:
        dashboard: 127.0.0.1:8080
      datasource:
        flow:
          zk:
            server-addr:  zk地址 
            groupId: sentinel_rule_config/SENTINEL_GROUP
            dataId: ${spring.application.name}/flow-rules
            #data-type: json
            # 规则类型,取值见:
            # org.springframework.cloud.alibaba.sentinel.datasource.RuleType
            rule-type: flow
          #熔断降级 名称随意
          degrade:
            zk:
              server-addr:  zk地址 
              groupId: sentinel_rule_config/SENTINEL_GROUP
              dataId: ${spring.application.name}/degrade-rules
              rule-type: degrade

            #系统规则 名称随意
            system:
              zk:
                server-addr: zk地址 
                groupId: sentinel_rule_config/SENTINEL_GROUP
                dataId: ${spring.application.name}/system-rules
                rule-type: system

            #授权规则 名称随意
            authority:
              zk:
                server-addr: zk地址 
                groupId: sentinel_rule_config/SENTINEL_GROUP
                dataId: ${spring.application.name}/authority-rules
                rule-type: authority

            #参数规则 名称随意
            param-flow:
              zk:
                server-addr: zk地址 
                groupId: sentinel_rule_config/SENTINEL_GROUP
                dataId: ${spring.application.name}/param-flow-rules
                rule-type: param-flow

 

3、测试
   在sentinel 客户端增加 接口的 熔断规则后 访问该接口 出现如下场景 即是成功

springcloud 集成Sentinel 1.8持久化到zookeeper

 

上一篇:flask-路由系统


下一篇:笔记:CentOS操作