当前位置:网站首页>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
边栏推荐
- Keil RVMDK compiled data type
- Can filter
- WiFi ap6212 driver transplantation and debugging analysis technical notes
- Gson fastjason Jackson of object to JSON difference modifies the field name
- 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
- Dynamically add default fusing rules to feign client based on sentinel + Nacos
- 解决:cnpm : 无法加载文件 ...\cnpm.ps1,因为在此系统上禁止运行脚本
- QT tablewidget insert qcombobox drop-down box
- Daily CISSP certification common mistakes (April 12, 2022)
- 14 py games source code share the second bullet
猜你喜欢

Nodejs installation

Notepad + + replaces tabs with spaces

Query the logistics update quantity according to the express order number

Creation and use of QT dynamic link library

Ctfshow - web362 (ssti)

Custom prompt box MessageBox in QT

Resolution: cnpm: unable to load file \cnpm. PS1, because running scripts is prohibited on this system

【ACM】376. 摆动序列

Solution to Chinese garbled code after reg file is imported into the registry

Dynamically add default fusing rules to feign client based on sentinel + Nacos
随机推荐
Daily CISSP certification common mistakes (April 19, 2022)
K210串口通信
配置iptables
Test questions of daily safety network (February 2024)
Setting up keil environment of GD single chip microcomputer
【ACM】70. climb stairs
QT tablewidget insert qcombobox drop-down box
QT curve / oscilloscope customplot control
视频边框背景如何虚化,简单操作几步实现
Daily CISSP certification common mistakes (April 18, 2022)
If condition judgment in shell language
The connection of imx6 network port is unstable after power on
Database computer experiment 4 (data integrity and stored procedure)
CISSP certified daily knowledge points (April 19, 2022)
Hard core parsing promise object (do you know these seven common APIs and seven key questions?)
Quantexa CDI(场景决策智能)Syneo平台介绍
【ACM】455. Distribute Biscuits (1. Give priority to big biscuits to big appetite; 2. Traverse two arrays with only one for loop (use subscript index -- to traverse another array))
On iptables
使用晨曦记账本,分析某个时间段每个账户收支结余
Introduction to QT programming