zoukankan      html  css  js  c++  java
  • Spring Cloud sentinel使用总结

    1 配置限流

    spring:
      application:
        name: service-feign
      cloud:
          sentinel:
            transport:
              port: 8719
              dashboard: 192.168.0.105:8080
              clientIp: 192.168.0.105
            datasource:
              ds1:
                file:
                  file: classpath:flowRule.json
                  data-type: json
                  rule-type: flow
    [{
    
        "resource":"sayHiFromClientOne",//必填项,资源名称可以是方法
        "count":1,//必填项,限流阈值 单位是每秒
        "grade": 1,//0:线程数(客户端并发控制)1:QPS(默认)
        "limitApp": "default",
        "strategy" : 0,//
    判断的根据是资源自身,还是根据其它关联资源 (refResource),还是根据链路入口 根据资源本身
    "controlBehavior": 0 //0:直接拒绝(默认)2:匀速通过
    }]

    2 配置熔断

      熔断的配置可以配在实际的服务类也可以配在负载均衡客户端,比如ribbon和feign

    @Service
    public class HelloService {
    
        @Autowired
        RestTemplate restTemplate;
    
    //    @HystrixCommand(fallbackMethod = "hiError")
        @SentinelResource(value= "hiService", blockHandler  ="hiErrorLimit" ,fallback = "hiErrorFallback")
        public String hiService(String name) {
            return restTemplate.getForObject("http://SERVICE-HI/hi?name="+name,String.class);
        }
    
        public String hiErrorLimit(String name) {
            return "hi,"+name+",limit!";
        }
    
        public String hiErrorFallback(String name) {
            return "hi,"+name+",fallback!";
        }
    
    }
  • 相关阅读:
    大数据(7)
    大数据(6)
    大数据(5)
    大数据(4)
    头发护理 -- 生发养发
    Sublime 中 SFTP插件的使用
    大数据(3)
    Apache Spark源码走读之5 -- DStream处理的容错性分析
    Apache Spark源码走读之4 -- DStream实时流数据处理
    Apache Spark源码走读之3 -- Task运行期之函数调用关系分析
  • 原文地址:https://www.cnblogs.com/juniorMa/p/14432427.html
Copyright © 2011-2022 走看看