当前位置:网站首页>将 Sentinel 熔断限流规则持久化到 Nacos 配置中心
将 Sentinel 熔断限流规则持久化到 Nacos 配置中心
2022-08-04 13:33:00 【InfoQ】
Nacos 配置中心配置持久化规则
集成到 Spring Cloud Alibaba微服务项目
在 Nacos 中配置流控规则
- resource :资源名,资源名是限流规则的作用对象,比如请求资源 getUser 。
- grade :限流阈值类型,QPS 或线程数模式。0表示线程数,1表示QPS。默认为1,即 QPS 模式
- count :限流阈值。比如值为2表示1秒超过2个请求就限流。
- strategy :流控模式:直接、链路、关联,默认 直接 。0表示直接,1表示关联,2表示链路。
- controlBehavior :流控效果(直接拒绝 / 排队等待 / 慢启动模式),0表示快速失败,1表示Warm Up,2表示排队等待。
- limitApp :流控针对的调用来源。默认就是 default ,代表不区分调用来源.
- resource :资源名,资源名是限流规则的作用对象,比如请求资源 getUser 。
- grade :熔断策略,支持慢调用比例/异常比例/异常数策略。1:慢调用比例,2:异常比例,3:异常数。默认为1,慢调用比例。
- count :慢调用比例模式下为慢调用临界 RT(超出该值计为慢调用);异常比例/异常数模式下为对应的阈值。
- timeWindow :熔断时长,单位为秒。
- minRequestAmount :熔断触发的最小请求数,请求数小于该值时即使异常比率超出阈值也不会熔断。默认为 5 。
- statIntervalMs :统计时长(单位为 ms),如 60*1000 代表分钟级。默认为 1000 ms。
- slowRatioThreshold :慢调用比例阈值,仅慢调用比例模式有效
Spring Cloud Alibaba 微服务项目中设置 Sentinel 数据源
<!-- 引入 Sentinel 数据源 -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-sentinel-datasource</artifactId>
</dependency>
<!-- Sentinel数据源之 Nacos -->
<dependency>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-datasource-nacos</artifactId>
</dependency>server:
port: 7072
spring:
application:
name: cloud-sentinel-service
cloud:
nacos:
discovery:
server-addr: 192.168.242.112:81
sentinel:
transport:
dashboard: localhost:8080
port: 8719
# https://github.com/alibaba/Sentinel/issues/1213
web-context-unify: false
datasource:
nacos:
nacos:
serverAddr: 192.168.242.112:81
groupId: DEFAULT_GROUP
dataId: sentinelFlowRule.json
ruleType: flow
management:
endpoints:
web:
exposure:
include: '*'[
{
"resource": "getUser",
"limitApp": "default",
"grade": 1,
"count": 2,
"strategy": 0,
"controlBehavior": 0,
"clusterMode": false
},
{
"resource": "getOrder",
"limitApp": "default",
"grade": 1,
"count": 2,
"strategy": 0,
"controlBehavior": 0,
"clusterMode": false
}
]@GetMapping("/getUser")
@SentinelResource("getUser")
public String getUser() {
return "getUser success!";
}
@GetMapping("/getOrder")
@SentinelResource("getOrder")
public String getOrder() {
return "getOrder success!";
}验证限流规则

小结
边栏推荐
- npm install出现的各种问题
- 错误 AttributeError type object 'Callable' has no attribute '_abc_registry' 解决方案
- vcl啥意思_oval
- VBS函数应用–getobject的使用获得Automation对象
- sqlserver删除重复数据
- 秋招攻略秘籍,吃透25个技术栈Offer拿到手软
- rpm安装提示error: XXX: not an rpm package (or package manifest):
- AutoCAD DWG,DXF文件导出高清图片、PDF
- LeetCode 1403 Minimum subsequence in non-increasing order [greedy] HERODING's LeetCode road
- CLS-PEG-DBCO,胆固醇-聚乙二醇-二苯基环辛炔,可用于改善循环时间
猜你喜欢

跨链桥已成行业最大安全隐患 为什么和怎么办

【解决方案 三十一】Navicat数据库结构同步

Unity 3D模型展示框架篇之资源打包、加载、热更(Addressable Asset System | 简称AA)

烂大街的缓存穿透、缓存击穿和缓存雪崩,你真的懂了?

nVisual secondary development - Chapter 2 nVisual API operation guide Swagger use

【WeChat Mini Program】Social Internship Production Project for Information Management and Information System Major--Trash Fingerprint

MFC的相机双目标定界面设计

牛客网刷题记录 || 链表

面试官:说一下NIO和BIO的区别

持续交付(二)PipeLine基本使用
随机推荐
router---Programmatic navigation
荧光磷脂PEG衍生物之一磷脂-聚乙二醇-荧光素,Fluorescein-PEG-DSPE
Launcher app prediction
MFC的相机双目标定界面设计
《会面》-凯瑟琳曼斯菲尔德(徐志摩译)
用过Apifox这个API接口工具后,确实感觉postman有点鸡肋......
Install mysql on k8s
Various problems with npm install
How to play the Tower of Hanoi
备份控制文件
odoo13 note point
【LeetCode】1403. 非递增顺序的最小子序列
Interviewer: How to view files containing abc string in /etc directory?
座舱人机交互「暗潮汹涌」,语音「下」,多模态「上」
【LeetCode】38、外观数列
跨链桥已成行业最大安全隐患 为什么和怎么办
router---mode
router---dynamic route matching
Motion Rule (16)-Union Check Basic Questions-Relations
新 Nsight Graph、Nsight Aftermath 版本中的性能提升和增强功能