Skip to content
本页导航

限流与降级

本框架包已集成 Alibaba Spring Cloud Sentinel 限流与降级包

使用方法

  • 自定义SDK模块需引入 spring-cloud-investoday-cloud

  • spring cloud investoday starter 2.7.3-SNAPSHOT及以上版本

  • application.properties

    #禁用,默认为true

    spring.cloud.sentinel.enabled=false

    #限流规则

    spring.cloud.sentinel.datasource.ds1.file.file=classpath:sentinel/flowRule.json spring.cloud.sentinel.datasource.ds1.file.data-type=json spring.cloud.sentinel.datasource.ds1.file.rule-type=flow

    #降级规则

    spring.cloud.sentinel.datasource.ds2.file.file=classpath:sentinel/degradeRule.json spring.cloud.sentinel.datasource.ds2.file.data-type=json spring.cloud.sentinel.datasource.ds2.file.rule-type=degrade

  • resources目录下新增 sentinel/flowRule.json 或 sentinel/degradeRule.json

    sentinel和本地配置规则文件

    限流参考

    [{ "resource": "/limit-rate/1", "count": 1, "grade": 1, "limitApp": "default", "strategy": 0 }]

  • 更多的配置见[官方网站](introduction | Sentinel (sentinelguard.io))

返回码

限流

code: Sen.ToManyRequests

message: 请求过于频繁

熔断

code: Sen.APIDegrade

message: API已降级

热点参数

code: Sen.ParamLimitRate

message: 热点参数请求过于频繁

权限控制

code: Sen.AuthorityLimit

message: 访问权限限制

lhiro