当前位置:网站首页>将 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!";
}验证限流规则

小结
边栏推荐
猜你喜欢

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

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

SCA兼容性分析工具(ORACLE/MySQL/DB2---&gt;MogDB/openGauss/PostgreSQL)

企业应当实施的5个云安全管理策略

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

MySQL性能指标TPS\QPS\IOPS如何压测?

Interviewer: How to view files containing abc string in /etc directory?

橄榄枝大课堂APP正式启动上线

《社会企业开展应聘文职人员培训规范》团体标准在新华书店上架

国家安全机关对涉嫌危害国家安全犯罪嫌疑人杨智渊实施刑事拘传审查
随机推荐
odoo13 note point
座舱人机交互「暗潮汹涌」,语音「下」,多模态「上」
php中的ceil和floo以及round函数「建议收藏」
从零开始配置 vim(6)——缩写
到底什么是真正的HTAP?
Arduino框架下I2S控制ADC采样以及PWM输出示例解析
d不要直接用转串
JSX使用
LeetCode 1403 非递增顺序的最小子序列[贪心] HERODING的LeetCode之路
双目立体视觉笔记(三)三角测量、极线校正
2546 饭卡(01背包,挺好的)
《社会企业开展应聘文职人员培训规范》团体标准在新华书店上架
VBS函数应用–getobject的使用获得Automation对象
永磁同步电机FOC驱动代码讲解
"Social Enterprises Conducting Civilian Personnel Training Specifications" group standard on the shelves of Xinhua Bookstore
21天学习挑战赛--第二天打卡(setSystemUiVisibility、导航栏、状态栏)
AutoCAD DWG,DXF文件导出高清图片、PDF
如何查找endnote文献中pdf文件的位置
Programmer Qixi Gift - How to quickly build an exclusive chat room for your girlfriend in 30 minutes
Opencv学习之ORB特征提取和匹配