什么是Sentinel
Sentinel也是Spring Cloud Alibaba的组件
Sentinel英文翻译"哨兵\门卫"
随着微服务的流行,服务和服务之间的稳定性变得越来越重要。Sentinel 以流量为切入点,从流量控制、熔断降级、系统负载保护等多个维度保护服务的稳定性。
基本配置和限流效果
我们的限流针对的是控制器方法
我们找一个简单的模块来测试和观察限流效果
在csmall-stock-webapi模块中
添加sentinel的依赖
```xml
<!-- Sentinel依赖 -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
</dependency>
```
application-dev.yml文件添加配置
```yaml
spring:
cloud:
sentinel:
transport:
dashboard: localhost:8080 # 配置sentinel仪表台的位置
# 执行限流的端口,每个项目唯一(别的项目(例如cart)设置的话不能再用8721)
port: 8721
nacos:
discovery:
server-addr: localhost:8848
下面进行限流操作
在要限流的控制器方法前添加注解