Sentinel规则持久化
在Sentinel中配置了规则之后,如果微服务重启之后,Sentinel中的规则就会消失,每次重启之后还需要重新进行配置
那么Sentinel可否进行持久化呢?答案当然是可以了,下面就测试一下将规则持久化到nacos中
依赖
1 2 3 4 5
| <dependency> <groupId>com.alibaba.csp</groupId> <artifactId>sentinel-datasource-nacos</artifactId> </dependency>
|
配置
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| spring: application: name: springcloudalibaba-sentinel cloud: sentinel: transport: dashboard: localhost:8080 port: 8719 datasource: ds1: nacos: server-addr: localhost:8848 dataId: ${spring.application.name} groupId: DEFAULT_GROUP data-type: json rule-type: flow nacos: discovery: server-addr: localhost:8848
|
nacos配置
在nacos中新建配置
其中dataId为微服务的spring.application.name,格式为json
内容为
1 2 3 4 5 6 7 8 9 10 11
| [ { "resource": "/testPersistence", "limitApp": "default", "grade": 1, "count": 1, "strategy": 0, "controlBehavior": 0, "clusterMode": false } ]
|
此时再次重启微服务之前配置的规则就可以直接从nacos中获取