请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

IllegalArgumentException 异常也会出现降级?

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来次就出现降级。

https://img1.sycdn.imooc.com//szimg/5f84150a0947b13d20020430.jpg

正在回答 回答被采纳积分+3

1回答

大目 2020-10-12 17:52:02

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

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

0 回复 有任何疑惑可以回复我~
问题已解决,确定采纳
还有疑问,暂不采纳
意见反馈 帮助中心 APP下载
官方微信