当前位置:网站首页>Sentinel规则持久化进Nacos
Sentinel规则持久化进Nacos
2022-04-23 18:36:00 【华为云】
@toc
源码地址:gitee代码仓库地址
1、为什么要将Sentienl规则持久化?
一旦我们重启应用,sentinel规则将消失,生产环境需要将配置规则进行持久化
2、持久化的思路
我们现在将限流配置规则持久化进Nacos保存,只要刷新8401某个rest地址,sentinel控制台的流控规则就能看到,只要Nacos里面的配置不删除,针对8401上sentinel上的流控规则持续有效。
3、操作步骤
3.1 项目中引入依赖
<!--SpringCloud ailibaba sentinel-datasource-nacos --><dependency> <groupId>com.alibaba.csp</groupId> <artifactId>sentinel-datasource-nacos</artifactId></dependency>
3.2 添加Nacos数据源配置
application.yml
server: port: 8401spring: application: name: cloudalibaba-sentinel-service cloud: nacos: discovery: #Nacos服务注册中心地址 server-addr: localhost:8848 sentinel: transport: #配置Sentinel dashboard地址 dashboard: localhost:8080 #默认8719端口,假如被占用会自动从8719开始依次+1扫描,直至找到未被占用的端口 port: 8719 datasource: ds1: #添加nacos数据源的配置,将sentinel配置持久化进nacos里面 nacos: server-addr: localhost:8848 dataId: cloudalibaba-sentinel-service groupId: DEFAULT_GROUP data-type: json rule-type: flowmanagement: endpoints: web: exposure: include: '*'
3.3 添加Nacos业务规则配置
[ { "resource": "/rateLimit/byUrl", "limitApp": "default", "grade": 1, "count": 1, "strategy": 0, "controlBehavior": 0, "clusterMode": false }]
resource:资源名称;
limitApp:来源应用;
grade:阈值类型,0表示线程数,1表示QPS;
count:单机阈值;
strategy:流控模式,0表示直接,1表示关联,2表示链路;
controlBehavior:流控效果,0表示快速失败,1表示Warm Up,2表示排队等待;
clusterMode:是否集群。
3.4 启动sentinel
3.5 此时启动8401微服务并刷新Sentinel
发现业务规则有了。
nacos上面:
sentinel上面:
3.6 测试
我们上面配置的意思是,该接口每秒只能处理1个请求,那我们频繁刷新请求,看看限流规则是否生效。
先正常访问:http://localhost:8401/rateLimit/byUrl
频繁访问:http://localhost:8401/rateLimit/byUrl
可以看到,触发了限流规则。这里我们程序中并没有指定blockHandler,所以显示的是默认限流之后的信息。
3.7 停止8401微服务查看
停止8401发现流控规则没有了。
3.8 重启8401微服务再看sentinel
还是没有,我们访问一次http://localhost:8401/rateLimit/byUrl,再刷新Sentinel
配置出现了,持久化验证通过。
版权声明
本文为[华为云]所创,转载请带上原文链接,感谢
https://bbs.huaweicloud.com/blogs/349221
边栏推荐
- Resolves the interface method that allows annotation requests to be written in postman
- 机器学习理论基础篇--关于机器学习的一些术语
- 14 py games source code share the second bullet
- 视频边框背景如何虚化,简单操作几步实现
- MATLAB从入门到精通(二)
- 教你用简单几个步骤快速重命名文件夹名
- Ucosiii transplantation and use, reference punctual atom
- Use stm32cube MX / stm32cube ide to generate FatFs code and operate SPI flash
- From introduction to mastery of MATLAB (2)
- Introduction to quantexa CDI syneo platform
猜你喜欢
Imx6 debugging LVDS screen technical notes
Introduction to quantexa CDI syneo platform
From introduction to mastery of MATLAB (2)
listener. log
ESP32 LVGL8. 1 - label (style 14)
STM32学习记录0008——GPIO那些事1
iptables -L执行缓慢
Excel intercept text
Install the yapiupload plug-in in idea and upload the API interface to the Yapi document
Matlab tips (6) comparison of seven filtering methods
随机推荐
QT reading and writing XML files (including source code + comments)
SQL中函数 decode()与 replace()的用法
根据快递单号查询物流查询更新量
Introduction to quantexa CDI syneo platform
Domestic GD chip can filter
The first leg of the national tour of shengteng AI developer creation and enjoyment day was successfully held in Xi'an
SQL database syntax learning notes
Install the yapiupload plug-in in idea and upload the API interface to the Yapi document
数据库上机实验四(数据完整性与存储过程)
Introduction to QT programming
CANopen STM32 transplantation
Dynamically add default fusing rules to feign client based on sentinel + Nacos
视频边框背景如何虚化,简单操作几步实现
ctfshow-web362(SSTI)
Solution to Chinese garbled code after reg file is imported into the registry
QT add external font ttf
ctfshow-web361(SSTI)
关于unity文件读取的操作(一)
The vivado project corresponding to the board is generated by TCL script
Résolution: cnpm: impossible de charger le fichier... Cnpm. PS1 parce que l'exécution de scripts est désactivée sur ce système