Sentine自定义限流异常

目录

1. sentinel 1.7版本(含)一下

2. sentinel 1.8 

3. 一共有3中方法

第一种:在springboot项目中,直接使用统一异常处理    

4. 参考链接


1. sentinel 1.7版本(含)一下

https://cloud.tencent.com/developer/article/1645215

 

2. sentinel 1.8 

https://blog.csdn.net/u011684553/article/details/108789968

 

3. 一共有3中方法


sentinel异常处理优先级 :@SentinelResource中定义了 blockHandler 和 faidback 属性  > UrlBlockHandler 和  BlockExceptionHandler  > 统一异常处理

第一种:在springboot项目中,直接使用统一异常处理    

/**
     * 替换默认流控提示内容:Blocked by sentinel(flow limiting)
     * 流控规则异常处理
     * 如果 @SentinelResource中定义了 blockHandler 和 faidback 属性,则此处不会捕获,以为 blockHandler 和 failback的优先级最高。
     * 限流处理、法一
     */
    @ExceptionHandler({FlowException.class})
    public R handleRRException(FlowException e){
        logger.error(RespConstant.RESP_MSG_FLOW_LIMITING_EXCEPTION, e);
        return RespUtils.commonHandle(RespConstant.RESP_CODE_FLOW_LIMITING_EXCEPTION, RespConstant.RESP_MSG_FLOW_LIMITING_EXCEPTION);
    }

    /**
     * 服务降级异常处理
     */
    @ExceptionHandler({DegradeException.class})
    public R handleRRException(DegradeException e){
        logger.error(RespConstant.RESP_MSG_DEGRADE_EXCEPTION, e);
        return RespUtils.commonHandle(RespConstant.RESP_CODE_DEGRADE_EXCEPTION, RespConstant.RESP_MSG_DEGRADE_EXCEPTION);
    }

    /**
     * 处理流量控制异常处理
     */
    @ExceptionHandler({AuthorityException.class})
    public R handleRRException(AuthorityException e){
        logger.error(RespConstant.RESP_MSG_AUTHORITY_EXCEPTION, e);
        return RespUtils.commonHandle(RespConstant.RESP_CODE_AUTHORITY_EXCEPTION, RespConstant.RESP_MSG_AUTHORITY_EXCEPTION);
    }

    /**
     * 处理流量控制异常处理
     */
    @ExceptionHandler({ParamFlowException.class})
    public R handleRRException(ParamFlowException e){
        logger.error(RespConstant.RESP_MSG_PARAM_FLOW_EXCEPTION, e);
        return RespUtils.commonHandle(RespConstant.RESP_CODE_PARAM_FLOW_EXCEPTION, RespConstant.RESP_MSG_PARAM_FLOW_EXCEPTION);
    }

    /**
     * 处理流量控制异常处理
     */
    @ExceptionHandler({SystemBlockException.class})
    public R handleRRException(SystemBlockException e){
        logger.error(RespConstant.RESP_MSG_SYSTEM_BLOCK_EXCEPTION, e);
        return RespUtils.commonHandle(RespConstant.RESP_CODE_SYSTEM_BLOCK_EXCEPTION, RespConstant.RESP_MSG_SYSTEM_BLOCK_EXCEPTION);
    }


    
    
第2种和第3种


        参考这里
    https://cloud.tencent.com/developer/article/1645215    

 

4. 参考链接

    https://cloud.tencent.com/developer/article/1645215    

https://blog.csdn.net/u011684553/article/details/108789968

https://cloud.tencent.com/developer/article/1645215

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值