- pom添加依赖
<dependency> <groupId>com.alibaba.csp</groupId> <artifactId>sentinel-datasource-nacos</artifactId> </dependency>
- 添加nacos配置
spring: cloud: sentinel: datasource: ds: nacos: server-addr: 127.0.0.1:8848 # namespace: public # 注意public空间下不能显示的设置为public否则获取不到配置 dataId: sentinel-client-app-sentinel.json groupId: DEFAULT_GROUP data-type: json rule-type: flow
- 编写Controller测试Sentinel
@RestController @RequestMapping("/sentinel/datasource") public class SentinelDatasourceController { @GetMapping("/index") @SentinelResource("sentinelDatasourceIndex") public String index(){ return "hello world index" ; } }
- nacos中添加dataId为sentinel-client-app-sentinel.json的配置
[ { "resource": "sentinelDatasourceIndex", "limitApp": "default", "grade": 1, "count": 1, "strategy": 0, "controlBehavior": 0, "clusterMode": false } ]
- 注意如果在namespace为public下创建的配置,则编写配置时namespace必须为空
Sentinel持久限流化化规则到Nacos
于 2023-09-12 23:01:32 首次发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)