
本着先实践后理论
官方文档:https://github.com/alibaba/Sentinel/wiki
github地址,下载太慢?gitee地址给你
如果是windows在cmd输入下面命令
java -Dserver.port=8080 -Dcsp.sentinel.dashboard.server=localhost:8080 -Dproject.name=sentinel-dashboard -jar sentinel-dashboard-1.8.2.jar3.打开主界面
在浏览器中输入http://127.0.0.1:8080/#/login ,看到主界面
用户名及密码都是sentinel
com.alibaba.cloud spring-cloud-alibaba-sentinel 2.1.0.RELEASE
SpringBoot版本是2.3.6.RELEASE
spring.application.name=redpacket spring.cloud.sentinel.transport.dashboard=localhost:8080
配置也比较简单,写上应用名字,和刚才部署的dashboard控制版的ip:端口号
@RestController
public class TestController {
@SentinelResource(value = "test")
@GetMapping("/test")
public void grapRedPacket(){
System.out.println("test");
}
}
@SentinelResource注解:可以监控一个方法,不管是Controller还是service中的都可以。后面会有详细的说明。0
4.使用sentinel实现接口限流为test方法添加流控规则,QPS大于2时,拒绝请求
5.测试不断请求test方法
出现拒绝了的QPS