SpringCloud Alibaba 五(Sentinel介绍)

Sentinel是是什么?

随着微服务的流行,服务和服务之间的稳定性变得越来越重要。Sentinel 以流量为切入点,从流量控制、熔断降级、系统负载保护等多个维度保护服务的稳定性,说白了其实就是我们之前讲过的Hystrix。

Sentinel 主要特征

在这里插入图片描述
Sentinel官网地址: https://spring-cloud-alibaba-group.github.io/github-pages/greenwich/spring-cloud-alibaba.html#_spring_cloud_alibaba_sentinel
Sentinel中文介绍: https://github.com/alibaba/Sentinel/wiki

sentinel 分别两部分:

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

https://github.com/alibaba/Sentinel/releases
在这里插入图片描述
在这里插入图片描述
下载jar包,执行命令 java -jar sentinel-dashboard-1.8.3.jar.

访问地址: http://localhost:8080

登录账号密码均为 sentinel
在这里插入图片描述
我们在项目中新建Module : pcloud-alibaba-sentinel-service8004
在这里插入图片描述
在这里插入图片描述
修改pom文件:

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <parent>
    <artifactId>pcloud-alibaba</artifactId>
    <groupId>com.younger.pcloud.alibaba</groupId>
    <version>1.0-SNAPSHOT</version>
  </parent>

  <groupId>com.younger.pcloud.alibaba</groupId>
  <artifactId>pcloud-alibaba-sentinel-service8004</artifactId>
  <version>1.0-SNAPSHOT</version>

  <name>pcloud-alibaba-sentinel-service8004</name>

  <dependencies>
    <!--SpringCloud ailibaba nacos -->
    <dependency>
      <groupId>com.alibaba.cloud</groupId>
      <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
    </dependency>
    <!--SpringCloud ailibaba sentinel-datasource-nacos 持久化-->
    <dependency>
      <groupId>com.alibaba.csp</groupId>
      <artifactId>sentinel-datasource-nacos</artifactId>
    </dependency>
    <!--SpringCloud ailibaba sentinel -->
    <dependency>
      <groupId>com.alibaba.cloud</groupId>
      <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
    </dependency>
    <!--openfeign-->
    <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-openfeign</artifactId>
    </dependency>

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-devtools</artifactId>
      <scope>runtime</scope>
      <optional>true</optional>
    </dependency>
    <dependency>
      <groupId>cn.hutool</groupId>
      <artifactId>hutool-all</artifactId>
      <version>4.6.3</version>
    </dependency>
    <dependency>
      <groupId>org.projectlombok</groupId>
      <artifactId>lombok</artifactId>
      <optional>true</optional>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-test</artifactId>
      <scope>test</scope>
    </dependency>

  </dependencies>

</project>

新增application.yml文件:

server:
  port: 8004

spring:
  application:
    name: pcloud-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: '*'

新增启动类: SentinelServiceMain8004

package com.younger.pcloud.alibaba;

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

@EnableDiscoveryClient
@SpringBootApplication
public class SentinelServiceMain8004 {

    public static void main(String[] args) {
        SpringApplication.run(SentinelServiceMain8004.class,args);
    }
}

新增controller :
在这里插入图片描述
新增 SentinelServiceController 类:

package com.younger.pcloud.alibaba.controller;

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

@RestController
public class SentinelServiceController {

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

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

启动项目测试一下:
在这里插入图片描述
我们看我们的控制台啥也没有。
访问: http://localhost:8004/testA
在这里插入图片描述
访问: http://localhost:8004/testB
在这里插入图片描述
我们在看下Sentinel控制台:
在这里插入图片描述
这个说明Sentinel采用的是懒加载方式进行流量监控的,这个Sentinel 8080 正在监控微服务 8004.。

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
### 回答1: Spring Cloud Alibaba是一个开源的微服务框架,它包括了大组件: 1. Nacos:一个动态服务发现、配置管理和服务管理平台,支持Kubernetes和Spring Boot。 2. Sentinel:一个流量控制、熔断降级的组件,为微服务提供实时的监控和控制。 3. RocketMQ:一个分布式消息中间件,具有高吞吐量、低延迟、可靠性强等特点。 4. Dubbo:一个高性能的Java RPC框架,支持多种协议和负载均衡策略。 5. Seata:一个易于使用的分布式事务解决方案,支持各种SQL和NoSQL数据库。 ### 回答2: Spring Cloud Alibaba是一个基于Spring Cloud的生态体系,提供了一系列的阿里巴巴分布式系统解决方案,其中包含了大组件:Nacos、Sentinel、Dubbo、RocketMQ和Seata。 1. Nacos Nacos是阿里巴巴开源的一款注册中心和配置中心,它具有更灵活、更易于扩展、更强大的动态服务发现、配置管理和服务管理能力。 2. Sentinel Sentinel是一款面向分布式服务架构的实时流量控制、熔断降级降权、系统负载保护等多种服务保护功能的开源框架,它可以在几乎所有的微服务框架中无缝集成,具有强大的实时监控能力。 3. Dubbo Dubbo是一款高性能、轻量级的RPC框架,它可以帮助用户快速构建基于Java的分布式应用程序,提供了负载均衡、服务发现、服务治理等一系列微服务必备的组件。 4. RocketMQ RocketMQ是一个高性能、低延迟、高可用、分布式消息中间件,它可以支持海量的消息存储并且提供多种可靠的消息传输保障方式。 5. Seata Seata是一个易于使用、高效、稳定的分布式事务解决方案,它可以帮助用户解决分布式场景下的事务一致性问题,提供了多种分布式事务协调支持。 总之,Spring Cloud Alibaba提供了一整套基于阿里巴巴生态体系的分布式解决方案,其中包含了大关键组件,每个组件都有其特定的优势和作用,能够帮助用户更加轻松、高效地构建分布式应用程序。 ### 回答3: Spring Cloud Alibaba是阿里巴巴基于Spring Cloud打造的一个开源框架,它提供了一系列的全新的开源组件,包括Nacos、Sentinel、Dubbo、RocketMQ以及Seata。这个组件构成了Spring Cloud Alibaba的核心,同时也是区别于其他云原生框架的关键所在。 1. Nacos Nacos是一款面向微服务架构的服务发现和配置管理系统,它实现了细粒度的服务域名管理以及动态配置管理。Nacos可以作为服务注册中心、配置中心和元数据中心,同时,它支持多种协议,包括HTTP、DNS、gRPC等,方便了不同语言和框架之间的集成。 2. Sentinel Sentinel是一个强大的开源项目,用于服务保护和流量控制。例如,当一个服务请求量过大时,Sentinel可以通过限流、熔断和降级来保护服务。它还可以提供实时监控与告警功能。 3. Dubbo Dubbo是一个高性能的分布式服务框架,可以实现服务的注册、发现、调用和管理等功能。同时,Dubbo提供了多种通信协议和序列化方式,以适应不同的场景。 4. RocketMQ RocketMQ是一个分布式的消息中间件,类似于Kafka,但性能更高、容易扩展,并且支持多种消息模式。RocketMQ具备高密度发布和订阅功能,并支持点对点和广播模式。 5. Seata Seata是一种分布式事务处理解决方案,可以管理跨多个微服务的分布式事务。Seata提供了可靠的数据一致性,并支持多种数据库存储引擎。 总之,Spring Cloud Alibaba提供了一组强大的云原生组件,帮助开发人员快速构建微服务应用并管理它们。这些组件提供了可靠的服务注册、发现、限流、熔断、消息管理、分布式事务等功能,使得开发人员能够专注于业务逻辑的实现。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

youngerone123

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值