springcloud整合Sentinel使用Nacos存储规则, 在#yyds干货盘点# springcloud整合Sentinel实现接口限流 基础代码上进行修改。
1.代码实现:
添加依赖
<dependency>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-datasource-nacos</artifactId>
<version>1.5.2</version>
</dependency>
yml配置
spring:
application:
name: sentinel
cloud:
sentinel:
transport:
dashboard: localhost:8080
datasource:
ds:
nacos:
server-addr: localhost:8848 #nacos的地址
dataId: ${spring.application.name}-sentinel
groupId: DEFAULT_GROUP
data-type: json
rule_type: flow
server:
port: 8001
2.实现效果:
启动nacos,浏览器打开http://localhost:8848/nacos登录后再配置管理中的配置列表进行添加规则
启动sentinel-dashboard,浏览器打开http://localhost:8080/ 使用默认用户密码:sentinel进行登录
启动sentinel项目,浏览器打开http://localhost:8001/index, 然后刷新sentinel控制台页面,可以看到在nacos配置的规则在sentinel中的流控规则页面显示。