当前位置:网站首页>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
边栏推荐
- leetcode:2032. Values that appear in at least two arrays
- MySQL [aggregate function]
- The batch size does not have to be a power of 2!The latest conclusions of senior ML scholars
- 我把问烂了的MySQL面试题总结了一下
- I summed up the bad MySQL interview questions
- 【Pytorch】F.softmax()方法说明
- el-tooltip的使用
- Selenium自动化测试之Selenium IDE
- For enterprises in the digital age, data governance is difficult, but it should be done
- 对数字化时代的企业来说,数据治理难做,但应该去做
猜你喜欢
OAuth2:单点登陆客户端
使用CompletableFuture进行异步处理业务
SetoolKit User Guide
八大排序汇总及其稳定性
机器学习模型验证:被低估的重要一环
csdn发文助手问题
对数字化时代的企业来说,数据治理难做,但应该去做
Asynchronous processing business using CompletableFuture
The 232-layer 3D flash memory chip is here: the single-chip capacity is 2TB, and the transmission speed is increased by 50%
1小时直播招募令:行业大咖干货分享,企业报名开启丨量子位·视点
随机推荐
什么是消息队列呢?
深度剖析 Apache EventMesh 云原生分布式事件驱动架构
leetcode: 485. Maximum number of consecutive 1s
MySQL has played to such a degree, no wonder the big manufacturers are rushing to ask for it!
Analysis of the startup source code of hyperf (2) - how the request reaches the controller
Resnet&API
Four ways to clear the float and its principle understanding
Redis与分布式:哨兵模式
为什么 wireguard-go 高尚而 boringtun 孬种
SetoolKit使用指南
自制的数据库安全攻防题,相关靶机自己制作
机器学习模型验证:被低估的重要一环
【Pytorch】F.softmax()方法说明
Tortoise speed by "template"
ML、DL、CV常见的问题整理
C# List Usage List Introduction
The use of thread pool two
OAuth2:微服务权限校验Session共享
ERROR: Failed building wheel for osgeo
Comparison of Optical Motion Capture and UWB Positioning Technology in Multi-agent Cooperative Control Research