-
Notifications
You must be signed in to change notification settings - Fork 8.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
增加基于注解的流控和降级配置 #797
增加基于注解的流控和降级配置 #797
Conversation
Codecov Report
@@ Coverage Diff @@
## master #797 +/- ##
============================================
- Coverage 41.69% 41.45% -0.25%
- Complexity 1375 1377 +2
============================================
Files 304 306 +2
Lines 8766 8824 +58
Branches 1182 1189 +7
============================================
+ Hits 3655 3658 +3
- Misses 4663 4719 +56
+ Partials 448 447 -1
Continue to review full report at Codecov.
|
注解=写死,并不能灵活的控制 |
注解提供了一个方便易于管理的配置方案,目的是避免配置的分散和资源名手误引起的配置错误,减少机械化的流控编码,并不是强制必须使用. |
Hi, thanks for contributing. Some kinds of rules are complex (e.g. for Would you like to add your implementation in Awesome Sentinel list? |
很荣幸能加入到Awesome Sentinel list. |
You can submit a PR to add your implementation into the Awesome Sentinel :) |
Hi, any progress about the PR to |
见 #815, 已加到awesome-sentinel.md, 改awesome-sentinel.md后Travis CI check失败,真奇怪,又没改过代码 |
I've re-triggered the CI build and it has passed. |
Added to |
[RIP-9] Commit docs Example_OpenMessaging.md
[RIP-9] Commit docs Example_OpenMessaging.md
Describe what this PR does / why we need it
简化FlowRule和DegradeRule的配置,目前的配置方式是在需要降级的地方写上SentinelResource注解,
然后专门找个文件写FlowRule和DegradeRule,配置内容分散,resource名需要在多处拷贝,需要多加小心保持各处resource名的一致性,给代码维护增加负担.
使用注解定义FlowRule和DegradeRule后,资源名只需要出现一次, 限流和降级规则在定义SentinelResource处直接可见,降低配置分散度,维护起来比较轻松.
Does this pull request fix one issue?
Describe how you did it
1.增加一个BeanPostProcess类SentinelAnnotationBeanProcessor在每个bean生成时扫描SentinelResource注解,在有注解的方法上找FlowRuleDefine和DegradeRuleDefine注解,如果找到就记录下来.
2.所有bean加载完后,调用FlowRuleManager和DegradeRuleManager的loadRules方法加载第一步找到的所有rule.
Describe how to verify it
1.如果是Spring Boot项目, 在Starter类上加上EnableSentinel注解启用Sentinel.同时不再需要手工配置SentinelResourceAspect这个bean. Starter类看起来如下:


在定义SentinelResource资源的地方加上FlowRuleDefine和DegradeRuleDefine注解
2.如果是基于xml的Spring配置,需要在xml中额外配置上 SentinelAnnotationBeanProcessor 这个bean,之后FlowRuleDefine和DegradeRuleDefine的注解方法和上面一样
Special notes for reviews