Sentinel

image.png
image.png
image.png
image.png

安装Sentinel

  1. 去GitHub上找1.7.1版本
  2. 直接下载jar包
  3. 使用 java -jar 包名称启动

初始化演示工程

先启动nacos8848 和 sentinel8080
image.png

  1. 新建cloudalibaba-sentinel-service8401
  2. POM

    1. <dependency>
    2. <groupId>com.alibaba.cloud</groupId>
    3. <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
    4. </dependency>
    5. <dependency>
    6. <groupId>com.alibaba.csp</groupId>
    7. <artifactId>sentinel-datasource-nacos</artifactId>
    8. </dependency>
    9. <dependency>
    10. <groupId>com.alibaba.cloud</groupId>
    11. <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
    12. </dependency>
    13. <dependency>
    14. <groupId>org.springframework.cloud</groupId>
    15. <artifactId>spring-cloud-starter-openfeign</artifactId>
    16. </dependency>
  3. YML ```yaml server: port: 8401 spring: application: name: cloudalibaba-sentinel-service cloud: nacos: discovery:

     # Nacos服务注册中心地址
     server-addr: localhost:8848
    

    sentinel: transport:

     # 配置Sentinel Dashboard地址
     dashboard: localhost:8080
     # 默认8719端口,假如被占用会自动从8719开始一次+1扫描,直至找到未被占用的端口
     port: 8719
    

management: endpoints: web: exposure: include: ‘*’


4. 主启动
```java
package com.cedric.springcloud.alibaba;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;

/**
 * @author Cedric
 * @date 2022/4/14
 */
@SpringBootApplication
@EnableDiscoveryClient
public class MainApp8401 {

    public static void main(String[] args) {
        SpringApplication.run(MainApp8401.class, args);
    }
}
  1. Controller ```java package com.cedric.springcloud.alibaba.controller;

import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController;

/**

  • @author Cedric
  • @date 2022/4/14 */ @RestController public class FlowLimitController {

    @GetMapping(“/testA”) public String testA() {

     return "test-----A";
    

    }

    @GetMapping(“/testB”) public String testB() {

     return "test-----B";
    

    } } ```

  1. 测试

image.png

流控规则

基本介绍

image.png image.png
image.png

流控模式

直接