这篇文章是介绍使用Nacos来作为Sentinel的动态数据源,这个动态数据源是Sentinel加载Nacos中的数据,如果你是在Sentinel控制台新增的规则是不能反推送到Nacos的(很尬)
依赖
<dependency>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-datasource-nacos</artifactId>
<version>${sentinel-datasource.version}</version>
</dependency>
目前支持的动态数据源有下面这些,可以在 文档 中找到相应的依赖
配置文件
#配置Sentinel
spring:
cloud:
sentinel:
transport:
port: 8719
#图形化管理地址
dashboard: localhost:8888
datasource:
ds1:
nacos:
#nacos地址
server-addr: localhost:8848 #nacos的地址
#dataid
dataId: order-flow-rules
#nacos中的组
groupId: DEFAULT_GROUP
#存储类型
data-type: json
rule_type: flow
rule_type有flow、degrade、param-flow、system、authority这几种,分别对应流控规则、降级规则、热点规则、系统规则、授权规则,还有两种是gw-flow、gw-api-group这个是gateway的限流和分组
Nacos对应的配置
这样在你访问getInfo方法的时候,Sentinel就会加载Nacos中的配置文件在流控规则中添加一个规则