Sentinel
1.下载jar包
2.启动Sentinel-Dashboard
java -jar sentinel-dashboard-1.8.1.jar
访问:http://localhost:8080 u: sentinel p:sentinel
3.项目配置
引入jar包
<!--SpringCloud ailibaba sentinel -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
</dependency>
添加配置文件application.yml
spring:
cloud:
sentinel:
transport:
dashboard: localhost:8080 #配置Sentinel dashboard地址
port: 8719
添加注解@SentinelResource
@GetMapping(value = "/payment/get/{id}")
@SentinelResource
public CommonResult<Payment> getPaymentById(@PathVariable("id") Long id)
{
Payment payment = paymentService.getPaymentByIdTime(id);
if(payment != null)
return new CommonResult(200,"查询成功😊!,serverPort: "+serverPort,payment);
return new CommonResult(444,"没有对应记录,查询ID: "+id,null);
}
访问该接口后就会在sentinel-dashboard就可以看到该接口。