一.下载地址
**Tags · alibaba/Sentinel (github.com) **
二.添加依赖
<!-- 后续做持久化用-->
<dependency>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-datasource-nacos</artifactId>
<version>1.7.2</version>
</dependency>
<!--sentinel依赖 -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
<version>2.2.6.RELEASE</version>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
<version>2.1.0.RELEASE</version>
</dependency>
三.配置yml
server:
port: 8401
spring:
application:
name: cloudalibaba-sentinel-service
cloud:
nacos:
discovery:
server-addr: localhost:8848 #配置nacos地址
sentinel:
transport:
# 配置sentinel-dashboard地址
dashboard: localhost:8080
# 默认8719端口,假如端口被占用会自动从8719开始依次+1扫描,直到找到没被占用的端口
port: 8719
#消费者将要去访问微服务的名称(成功注册进nacos的微服务提供者)
management:
endpoints:
web:
exposure:
include: '*'
四.启动类
@SpringBootApplication
@EnableDiscoveryClient
public class Mainapp8401 {
public static void main(String[] args) {
SpringApplication.run(Mainapp8401.class,args);
}
}
五.controller
@RestController
public class sentinelController {
@GetMapping("/testA")
public String testA(){
return "testA";
}
@GetMapping("/testB")
public String testB(){
return "testB";
}
}
六.访问端口
在进入Sentinel界面
七.流控,降级,熔断
图片太多不展示了.