赞
踩
- <!-- sentinel持久化到nacos -->
- <dependency>
- <groupId>com.alibaba.csp</groupId>
- <artifactId>sentinel-datasource-nacos</artifactId>
- </dependency>
流控规则, 权限规则,降级规则,系统规则,授权规则,热点参数规则 配置到nacos中
- [
- {
- // 资源名
- "resource": "/test",
- // 针对来源,若为 default 则不区分调用来源
- "limitApp": "default",
- // 限流阈值类型(1:QPS;0:并发线程数)
- "grade": 1,
- // 阈值
- "count": 1,
- // 是否是集群模式
- "clusterMode": false,
- // 流控效果(0:快速失败;1:Warm Up(预热模式);2:排队等待)
- "controlBehavior": 0,
- // 流控模式(0:直接;1:关联;2:链路)
- "strategy": 0,
- // 预热时间(秒,预热模式需要此参数)
- "warmUpPeriodSec": 10,
- // 超时时间(排队等待模式需要此参数)
- "maxQueueingTimeMs": 500,
- // 关联资源、入口资源(关联、链路模式)
- "refResource": "rrr"
- }
- ]
![](https://csdnimg.cn/release/blogv2/dist/pc/img/newCodeMoreWhite.png)
- [
- {
- // 资源名
- "resource": "sentinel_spring_web_context",
- // 流控应用
- "limitApp": "/test",
- // 授权类型(0代表白名单;1代表黑名单。)
- "strategy": 0
- }
- ]
- [
- {
- // 资源名
- "resource": "/test1",
- "limitApp": "default",
- // 熔断策略(0:慢调用比例,1:异常比率,2:异常计数)
- "grade": 0,
- // 最大RT、比例阈值、异常数
- "count": 200,
- // 慢调用比例阈值,仅慢调用比例模式有效(1.8.0 引入)
- "slowRatioThreshold": 0.2,
- // 最小请求数
- "minRequestAmount": 5,
- // 当单位统计时长(类中默认1000)
- "statIntervalMs": 1000,
- // 熔断时长
- "timeWindow": 10
- }
- ]
![](https://csdnimg.cn/release/blogv2/dist/pc/img/newCodeMoreWhite.png)
- [
- {
- // RT
- "avgRt": 1,
- // CPU 使用率
- "highestCpuUsage": -1,
- // LOAD
- "highestSystemLoad": -1,
- // 线程数
- "maxThread": -1,
- // 入口 QPS
- "qps": -1
- }
- ]
- [
- {
- // 资源名
- "resource": "sentinel_spring_web_context",
- // 流控应用
- "limitApp": "/test",
- // 授权类型(0代表白名单;1代表黑名单。)
- "strategy": 0
- }
- ]
- [
- {
- // 资源名
- "resource": "/test1",
- // 限流模式(QPS 模式,不可更改)
- "grade": 1,
- // 参数索引
- "paramIdx": 0,
- // 单机阈值
- "count": 13,
- // 统计窗口时长
- "durationInSec": 6,
- // 是否集群 默认false
- "clusterMode": false,
- //
- "burstCount": 0,
- // 集群模式配置
- "clusterConfig": {
- //
- "fallbackToLocalWhenFail": true,
- //
- "flowId": 2,
- //
- "sampleCount": 10,
- //
- "thresholdType": 0,
- //
- "windowIntervalMs": 1000
- },
- // 流控效果(支持快速失败和匀速排队模式)
- "controlBehavior": 0,
- //
- "limitApp": "default",
- //
- "maxQueueingTimeMs": 0,
- // 高级选项
- "paramFlowItemList": [
- {
- // 参数类型
- "classType": "int",
- // 限流阈值
- "count": 222,
- // 参数值
- "object": "2"
- }
- ]
- }
- ]
![](https://csdnimg.cn/release/blogv2/dist/pc/img/newCodeMoreWhite.png)
yml文件配置和nacos中配置相对应
- spring:
- cloud:
- nacos:
- discovery:
- server-addr: localhost:8848 #Nacos 服务地址
- sentinel:
- eager: true #饿加载
- transport:
- dashboard: localhost:8089 #配置 Sentinel dashboard 地址
- datasource:
- flow: #流控规则
- nacos:
- namespace: 1efe62b0-b759-45ff-a5e7-4fb5c27350c7
- server-addr: localhost:8848
- dataId: ${spring.application.name}-flow-rules
- groupId: SENTINEL_GROUP
- data-type: json
- rule-type: flow
- degrade:
- nacos:
- namespace: 1efe62b0-b759-45ff-a5e7-4fb5c27350c7
- server-addr: localhost:8848
- dataId: ${spring.application.name}-degrade-rules
- groupId: SENTINEL_GROUP
- data-type: json
- rule-type: degrade
- system:
- nacos:
- namespace: 1efe62b0-b759-45ff-a5e7-4fb5c27350c7
- server-addr: localhost:8848
- dataId: ${spring.application.name}-system-rules
- groupId: SENTINEL_GROUP
- data-type: json
- rule-type: system
- authority:
- nacos:
- namespace: 1efe62b0-b759-45ff-a5e7-4fb5c27350c7
- server-addr: localhost:8848
- dataId: ${spring.application.name}-authority-rules
- groupId: SENTINEL_GROUP
- data-type: json
- rule-type: authority
- param-flow:
- nacos:
- namespace: 1efe62b0-b759-45ff-a5e7-4fb5c27350c7
- server-addr: localhost:8848
- dataId: ${spring.application.name}-param-flow-rules
- groupId: SENTINEL_GROUP
- data-type: json
- rule-type: param-flow
![](https://csdnimg.cn/release/blogv2/dist/pc/img/newCodeMoreWhite.png)
总结:
配置naocs中只能实现配置持久化,不能实现修改sentinel中规则改变nacos中的配置,如果想要实现,需要修改sentinel-dashboard.
修改sentinel-dashboard连接
sentinel基于nacos的持久化,改造sentinel-dashboard-1.8_小乚唠java的博客-CSDN博客
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。