IllegalArgumentException 异常也会出现降级?

来源:8-13 Sentinel API详解

hthonor

2020-10-12

sentinel dashboard 版本 1.7.1

spring cloud 版本 Hoxton.SR3

spring cloud alibaba  版本2.2.1.RELEASE


Java 代码

@GetMapping("/test-sentinel-api")
   public String testSentinelApi(
           @RequestParam(required = false) String a
   ){
       String resourceName="test-sentinel-api";
       Entry entry=null;
       try {
           //定义 sentinel 保护的资源,设置资源名
           entry= SphU.entry(resourceName);
           // 被保护的业务逻辑
           if(StringUtils.isBlank(a)){
               throw new IllegalArgumentException("a is null");
           }
           return a;
       } catch (BlockException e) {
           // 资源访问,被限流或被降级
           log.warn("限流,或者降级了",e);
           return "限流,或者降级了";
       }finally {
           // 务必保证 exit,务必保证每个 entry 与 exit 配对
           if(entry != null){
               entry.exit();
           }
       }
   }


设置了降级规则,频繁刷新 http://localhost:8010/test-sentinel-api,也会被降级,跟老师讲的不一样!!

有时候刷新30几次才出现降级,有时候刷新10来次就出现降级。

http://img.mukewang.com/szimg/5f84150a0947b13d20020430.jpg

写回答

1回答

大目

2020-10-12

哥,你的降级模式是 RT(响应时间)啊,这表示平均响应时间超过阈值就降级,和异常没啥关系哦。

将降级模式改为异常比例即可。

0
0

Spring Cloud Alibaba微服务从入门到进阶

面向未来微服务:熟练掌握Spring Cloud Alibaba

2975 学习 · 1299 问题

查看课程