概述
Sentinel是Alibaba开源的一套用于服务容错的综合性解决方案。他以流量为切入点,从流量控制,熔断降级,系统负载保护等多个维度来保护服务的稳定性。
Sentinel核心分为两部分:
- 核心库:能够运行于所有Java运行时环境,同时对Dubbo/Spring Cloud等框架也有比较好的支持
- 控制台:基于Spring Boot开发,打包后可直接运行
下载Sentinel
https://github.com/alibaba/Sentinel/releases
启动Sentinel
- 在sentinel对应目录,打开命令行(cmd),启动运行sentinel
java -Dserver.port=8180 -Dcsp.sentinel.dashboard.server=localhost:8180 -Dproject.name=sentinel-dashboard -jar sentinel-dashboard-1.8.1.jar
访问Sentinel
- localhost:8180
登录Sentinel
-
账号密码都是sentinel
Sentinel限流入门
-
导入sentinel依赖
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
</dependency>
-
配置bootstrap.yml文件
spring:
cloud:
sentinel:
transport:
dashboard: localhost:8180 # 指定sentinel控制台地址
-
创建一个用于演示限流的Controller
@RestController
@RequestMapping("/provider")
public class ProviderSentinelController {
@GetMapping("/sentinel01")
public String doSentinel01(){
return "sentinel 01 text.....";
}
}
- 设置指定接口接口流控