spring cloud alibaba sentinel 入门

 

Sentinel: 分布式系统的流量防卫兵

Sentinel 是什么?

随着微服务的流行,服务和服务之间的稳定性变得越来越重要。Sentinel 以流量为切入点,从流量控制、熔断降级、系统负载保护等多个维度保护服务的稳定性。

Sentinel 具有以下特征:

  • 丰富的应用场景:Sentinel 承接了阿里巴巴近 10 年的双十一大促流量的核心场景,例如秒杀(即突发流量控制在系统容量可以承受的范围)、消息削峰填谷、集群流量控制、实时熔断下游不可用应用等。
  • 完备的实时监控:Sentinel 同时提供实时的监控功能。您可以在控制台中看到接入应用的单台机器秒级数据,甚至 500 台以下规模的集群的汇总运行情况。
  • 广泛的开源生态:Sentinel 提供开箱即用的与其它开源框架/库的整合模块,例如与 Spring Cloud、Dubbo、gRPC 的整合。您只需要引入相应的依赖并进行简单的配置即可快速地接入 Sentinel。
  • 完善的 SPI 扩展点:Sentinel 提供简单易用、完善的 SPI 扩展接口。您可以通过实现扩展接口来快速地定制逻辑。例如定制规则管理、适配动态数据源等。

Sentinel 的主要特性:

 

Sentinel 的开源生态:

 

Sentinel 分为两个部分:

  • 核心库(Java 客户端)不依赖任何框架/库,能够运行于所有 Java 运行时环境,同时对 Dubbo / Spring Cloud 等框架也有较好的支持。
  • 控制台(Dashboard)基于 Spring Boot 开发,打包后可以直接运行,不需要额外的 Tomcat 等应用容器。
 

下载地址

使用jar -jar sentinel-dashboard-1.7.0.jar 
访问 localhost:8080
账号 密码 sentinel sentinel
 

管控服务

  1. 新增依赖
    <!--SpringCloud ailibaba sentinel -->
    <dependency>
    <groupId>com.alibaba.cloud</groupId>
    <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
    </dependency>
  2. 修改yml 连接sentinel
    spring:
      cloud:
        sentinel:
          transport:
            port: 8719
            dashboard: localhost:8080
  3. 测试类
    @RestController
    public class FlowLimitController {

    @GetMapping("/testA")
    public String testA(){
    return "A";
    }

    @GetMapping("/testB")
    public String testB(){
    return "B";
    }
    }
准备完成,开始启动服务并打开控制台,未发现有任何变化
sentinel 采用的是懒加载,需要先触发几次接口,访问 http://localhost:8001/testA
再次查看控制台
 
对资源可以进行 流控,降级, 热点词 和 授权控制
 
 

spring cloud gateway support

https://github.com/alibaba/Sentinel/wiki/%E7%BD%91%E5%85%B3%E9%99%90%E6%B5%81

spring cloud sentinel quickly start

https://spring-cloud-alibaba-group.github.io/github-pages/greenwich/spring-cloud-alibaba.html#_spring_cloud_alibaba_sentinel



原文地址:https://www.cnblogs.com/xues/p/13431874.html