规则持久化
基于Nacos配置中心实现推送
引入依赖
<dependency>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-datasource-nacos</artifactId>
</dependency>
流控配置文件
[
{
"resource":"/order/flow",
"controlBehavior":0,
"count":10.0,
"grade":1,
"limitApp":"default",
"strategy":0
}
]
![](https://img-blog.csdnimg.cn/direct/7ce927a2b68342719bec6dac585bffb7.png)
流控文件相关配置
server:
port: 8061
spring:
application:
name: order-sentinel
cloud:
sentinel:
transport:
dashboard: 127.0.0.1:8080
web-context-unify: false # 默认请求链路进行收敛
datasource:
flow-rule:
nacos:
server-addr: 127.0.0.1:8847
username: nacos
password: nacos
data-id: order-sentinel-flow-rule
group-id: SENTINEL_GROUP
rule-type: flow
重启服务、看效果
![](https://img-blog.csdnimg.cn/direct/f333d2c320044b219dc3c88d3ee09c56.png)
访问效果
![](https://img-blog.csdnimg.cn/direct/0ff063d04d344539b17a32b773cca6ad.png)
弊端
- Sentinel 上修改阈值后 无法同步到 nacos
- 需手动修改nacos中的配置保持 和 Sentinel 中的一致