当前位置:网站首页>sentinel与nacos持久化
sentinel与nacos持久化
2022-07-31 14:05:00 【Leon_Jinhai_Sun】
在流量控制那篇文章中,我们在sentinel中配置好A服务对应的限流策略后,如果A服务重启就会导致sentinel中配置好的策略丢失,所以需要持久化操作。
流量控制可以有三种方法配置:一种是在sentinel控制台进行配置(服务重启则配置的策略丢失),一种是在代码中进行编写控制,还有就是从nacos中读取进行持久化配置。
限流配置
[
{
“resource”:"/test", 需要限流的接口
“limitApp”:“default”,
“grade”:1, 阈值类型:1为QPS,0为线程数
“count”:3, 每秒钟单机阈值,超过就会报错
“strategy”:0, 流控模式 0直接,1关联,2链路
“controlBehavior”:0, 设置流控效果 ,0直接拒接,1 Warm up 预热,2排队等待
“clusterMode”:false
},
,
{
“resource”:“POST:http://manage-nacos/get/name”,
“limitApp”:“default”,
“grade”:1,
“count”:3,
“strategy”:0,
“controlBehavior”:0,
“clusterMode”:false
}
]
对应依赖
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<!-- sentinel 流量控制依赖-->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
<version>${spring-cloud-alibaba.version}</version>
</dependency>
<!-- sentinel 底层通过actuator来进行监控-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- 使用nacos作为sentinel持久化数据源 -->
<dependency>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-datasource-nacos</artifactId>
</dependency>
配置文件中进行配置,从nacos中读取配置信息
spring:
jackson:
default-property-inclusion: non_null # 全局jackson不对null做序列化输出
cloud:
# 将本服务与 sentinel监控进行绑定
sentinel:
transport:
dashboard: 127.0.0.1:8080
datasource:
flow-ds: #sentinel从nacos获取指定的流控规则 这个名字可以自定义,不重复就可以
nacos:
server-addr: 127.0.0.1:8848
dataId: flow-server
groupId: DEFAULT_GROUP
ruleType: flow # flow代表流程控制,degrade代表熔断规则
username: nacos
password: nacos
熔断配置
对应参数代表的含义请看 流程控制篇


[
{
"resource":"/test", 请求路径
"count":200, 每秒钟请求响应的平均时间,200就是一秒处理五个请求
"grade":0, 降级策略,0为RT平均响应时间
"timeWindow":5 熔断时间为5秒
}
]
服务对应的配置文件
spring:
jackson:
default-property-inclusion: non_null # 全局jackson不对null做序列化输出
cloud:
# 将本服务与 sentinel监控进行绑定
sentinel:
transport:
dashboard: 127.0.0.1:8080
datasource:
flow-ds: #sentinel从nacos获取指定的流控规则 这个名字可以自定义,不重复就可以
nacos:
server-addr: 127.0.0.1:8848
dataId: flow-server
groupId: DEFAULT_GROUP
ruleType: flow # flow代表流程控制,degrade代表熔断规则
username: nacos
password: nacos
grade-ds: #sentinel从nacos获取指定的熔断规则 这个名字可以自定义,不重复就可以
nacos:
server-addr: 127.0.0.1:8848
dataId: degrade-server
groupId: DEFAULT_GROUP
ruleType: degrade # flow代表流程控制,degrade代表熔断规则
username: nacos
password: nacos
边栏推荐
- 49. The copy constructor and overloaded 】
- Shell脚本经典案例:探测批量主机是否存活
- 小试牛刀:Go 反射帮我把 Excel 转成 Struct
- 最近很火的国产接口神器Apipost体验
- BigDecimal 简介,常用方法
- Shell project combat 1. System performance analysis
- 1-hour live broadcast recruitment order: industry leaders share dry goods, and enterprise registration is open丨qubit · point of view
- 1小时直播招募令:行业大咖干货分享,企业报名开启丨量子位·视点
- MySQL 23道经典面试吊打面试官
- 百度网盘安装在c盘显示系统权限限制的解决方法
猜你喜欢

Even if the image is missing in a large area, it can also be repaired realistically. The new model CM-GAN takes into account the global structure and texture details

为什么要分库分表?

Motion capture system for end-positioning control of flexible manipulators

C# using ComboBox control

Spark Learning: Add Custom Optimization Rules for Spark Sql

The batch size does not have to be a power of 2!The latest conclusions of senior ML scholars

C# control ToolStripProgressBar usage

MySQL 23道经典面试吊打面试官

I summed up the bad MySQL interview questions

一篇文章讲清楚!数据库和数据仓库到底有什么区别和联系?
随机推荐
使用CompletableFuture进行异步处理业务
技能大赛dhcp服务训练题
Shell script classic case: detecting whether a batch of hosts is alive
页面整屏滚动效果
“听我说谢谢你”还能用古诗来说?清华搞了个“据意查句”神器,一键搜索你想要的名言警句...
我把问烂了的MySQL面试题总结了一下
Uniapp WeChat small application reference standard components
IDEA connects to MySQL database and uses data
csdn发文助手问题
技能大赛训练题:MS15_034漏洞验证与安全加固
AI cocoa AI frontier introduction (7.31)
AWS实现定时任务-Lambda+EventBridge
技能大赛训练题:登录安全加固
The magic of SQL MERGE statement (detailed instructions)
Selenium自动化测试之Selenium IDE
技能大赛训练题:ftp 服务攻防与加固
endnote引用
为什么 wireguard-go 高尚而 boringtun 孬种
Combination series - there are combinations when there are arrangements
技能大赛训练题:交换机虚拟化练习