开发者学堂课程【精通 Spring Cloud Alibaba:项目启动加载限流规则代码】学习笔记,与课程紧密联系,让用户快速学习知识
课程地址:https://developer.aliyun.com/learning/course/634/detail/10138
项目启动加载限流规则代码
当我们 SpringBoot 项目启动成功之后,加载我们的限流的规则。
@Component
@Slf4j
public class SentinelAnplicationRunner implements ApplicationRunnec {
private static final String GETORDER_KEY ="getOrdec";
@Override
public void run(ApplicationArguments a
r
gs) throws Exception {
List<
F
lowRule>rules=new A
rr
a
vL
ist();
ElowRule rule1=new
F
lowRule();
rule1.setResource(GETORDER_KEY);
//QPS控制在2以内
rule1.setCount(1);
// QPS限流
rule1.setGrade(RuleConstant.FLOW GRADE OPS);
rule1.setLimitApp("default");
rules.add(rule1);
F
lowRuleManager
.
loadRules(rules);
Log.info(">>>限流服务接口配置加载成功>>>");
}
}