- pom添加依赖
<dependency>
<groupId>com.alibaba.cspgroupId>
<artifactId>sentinel-datasource-nacosartifactId>
dependency>
- 添加nacos配置
spring:
cloud:
sentinel:
datasource:
ds:
nacos:
server-addr: 127.0.0.1:8848
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必须为空