目录
简介
Sentinel概述
背景:某些时候,服务器流量暴涨,导致服务无法正常运转,需要对流量进行控制
Sentinel是什么?(阿里推出一个流量控制平台,防卫兵)
安装Sentinel服务
第一步:打开sentinel下载网址,下载Jar包
https://github.com/alibaba/Sentinel/releases
第二步:启动运行sentinel
java -Dserver.port=8180 -Dcsp.sentinel.dashboard.server=localhost:8180 -Dproject.name=sentinel-dashboard -jar sentinel-dashboard-1.8.1.jar
访问Sentinal服务
浏览器访问localhost:8180
Sentinel限流入门
准备工作
第一步:在服务提供方添加依赖
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
</dependency>
第二步:bootstrap.yml添加sentinel配置
spring:
cloud:
sentinel:
transport:
dashboard: localhost:8180 # 指定sentinel控制台地址。
第三步:创建一个用于演示限流操作的Controller对象
package com.jt.provider.controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@R