docs: update README.md

This commit is contained in:
xiongxiaoyang
2022-06-01 14:11:58 +08:00
parent 7f0d6c842a
commit c4fabe2ca1
2 changed files with 8 additions and 7 deletions

View File

@ -41,15 +41,15 @@ public class FlowLimitInterceptor implements HandlerInterceptor {
private final ObjectMapper objectMapper;
/**
* 定义一个对所有的请求进行统一限制的资源
* novel 项目所有的资源
*/
private static final String ALL_LIMIT_RESOURCE = "allLimitResource";
private static final String NOVEL_RESOURCE = "novelResource";
static {
// 接口限流规则:所有的请求,限制每秒最多只能通过 2000 个,超出限制匀速排队
List<FlowRule> rules = new ArrayList<>();
FlowRule rule1 = new FlowRule();
rule1.setResource(ALL_LIMIT_RESOURCE);
rule1.setResource(NOVEL_RESOURCE);
rule1.setGrade(RuleConstant.FLOW_GRADE_QPS);
// Set limit QPS to 2000.
rule1.setCount(2000);
@ -58,11 +58,11 @@ public class FlowLimitInterceptor implements HandlerInterceptor {
FlowRuleManager.loadRules(rules);
// 接口防刷规则 1所有的请求限制每个 IP 每秒最多只能通过 50 个,超出限制直接拒绝
ParamFlowRule rule2 = new ParamFlowRule(ALL_LIMIT_RESOURCE)
ParamFlowRule rule2 = new ParamFlowRule(NOVEL_RESOURCE)
.setParamIdx(0)
.setCount(50);
// 接口防刷规则 2所有的请求限制每个 IP 每分钟最多只能通过 1000 个,超出限制直接拒绝
ParamFlowRule rule3 = new ParamFlowRule(ALL_LIMIT_RESOURCE)
ParamFlowRule rule3 = new ParamFlowRule(NOVEL_RESOURCE)
.setParamIdx(0)
.setCount(1000)
.setDurationInSec(60);
@ -77,7 +77,7 @@ public class FlowLimitInterceptor implements HandlerInterceptor {
// 若需要配置例外项,则传入的参数只支持基本类型。
// EntryType 代表流量类型,其中系统规则只对 IN 类型的埋点生效
// count 大多数情况都填 1代表统计为一次调用。
entry = SphU.entry(ALL_LIMIT_RESOURCE, EntryType.IN, 1, ip);
entry = SphU.entry(NOVEL_RESOURCE, EntryType.IN, 1, ip);
// Your logic here.
return HandlerInterceptor.super.preHandle(request, response, handler);
} catch (BlockException ex) {