环境
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.5.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Hoxton.SR3</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
<version>2.2.1.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
服务端 Sentinel-dashboard
- 下载最新
Sentinel-dashboardjar包
- 运行jar包
java -jar sentinel-dashboard-1.7.1.jar -Dserver.port=8080 -Dcsp.sentinel.dashboard.server=localhost:8080 -Dproject.name=sentinel-dashboard
- 浏览器访问
http://localhost:8080
默认账号密码sentinel/sentinel
客户端
引入依赖
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
</dependency>
-
postman或curl调用下程序内接口,在sentinel dashboard中可以看到实时监控 -
配置限流规则
点击 簇点链路→选择接口→点击流控
如图配置,实现效果(限流策略):每秒最多允许2个请求进入 阈值类型:QPS 单机阈值:2
接口测试,快速调用第三次被sentinel限流