sentinel持久限流化化规则到nacos

  1. pom添加依赖
    <dependency>
        <groupId>com.alibaba.cspgroupId>
        <artifactId>sentinel-datasource-nacosartifactId>
    dependency>
    
  2. 添加nacos配置
    spring:
      cloud:
        sentinel:
          datasource:
            ds:
              nacos:
                server-addr: 127.0.0.1:8848
                # namespace: public  # 注意public空间下不能显示的设置为public否则获取不到配置
                dataId: sentinel-client-app-sentinel.json
                groupId: DEFAULT_GROUP
                data-type: json
                rule-type: flow
    
  3. 编写Controller测试Sentinel
    @RestController
    @RequestMapping("/sentinel/datasource")
    public class SentinelDatasourceController {
    
        @GetMapping("/index")
        @SentinelResource("sentinelDatasourceIndex")
        public String index(){
    
            return "hello world index" ;
        }
    }
    
  4. nacos中添加dataId为sentinel-client-app-sentinel.json的配置
    [
      {
        "resource": "sentinelDatasourceIndex",
        "limitApp": "default",
        "grade": 1,
        "count": 1,
        "strategy": 0,
        "controlBehavior": 0,
        "clusterMode": false
      }
    ]
    
  5. 注意如果在namespace为public下创建的配置,则编写配置时namespace必须为空

你可能感兴趣的:(sentinel,开发语言,java)