3.服务降级:Sentinel

0.1概念

        一个强大的流控制组件,可实现微服务的可靠性,弹性和监视。

        Sentinel以“流”为切入点,并在流控制, 流量整形,电路中断和系统自适应保护等多个领域工作,以确保微服务的可靠性和弹性。

        Sentinel具有以下功能:

                丰富的适用场景

                实时监控

                广泛的开源生态系统

                多种语言支持

        官网:https://github.com/alibaba/Sentinel

        下载:https://github.com/alibaba/Sentinel/releases

        怎么玩:服务雪崩、服务降级、服务熔断、服务限流

0.2安装

        sentinel分为两个部分:

        核心库:不依赖任何框架/库,能够运行于所有java运行时环境,同时对Dubbo/Spring Cloud等框架也有较好的支持。

        控制台(Dashboard):基于springboot开发,打包后可以直接运行,不需要额外的Tomcat等应用容器。

        安装步骤:

                本次下载sentinel-dashboard-1.7.0.jar这个版本

                运行命令,到sentinel的所在目录下:java -jar sentinel-dashboard-1.7.0.jar

                访问sentinel管理界面:http://localhost:8080/#/login,账号密码均为sentinel

0.3Sentinel的初步使用

        (1)先启动Nacos注册中心

        (2)创建Maven工程作为服务提供者(cloudalibab-sentinel-service8401)

        (3)添加Nacos和Sentinel依赖

<!--sentinel-->
<dependency>
    <groupId>com.alibaba.cloud</groupId>
    <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
</dependency>
<!--服务注册中心依赖-->

         (4)application.yml

server:
  port: 8401
spring:
  application:
    name: cloudalibaba-sentinel-service
  cloud:
    nacos:
      discovery:
        server-addr: localhost:8848 #nacos服务注册中心地址
    sentinel:
      transport:
        dashboard: localhost:8080 #配置sentinel 控制台(dashboard)地址,使8080监控8401
        port: 8719  #默认8719,假如被占用了会自动从8719开始依次+1扫描。直至找到未被占用的端口
management: #暴露监控的端点
  endpoints:
    web:
      exposure:
        include: '*'

        (5)Controller

@RestController
public class FlowLimitController
{
    @GetMapping("/testA")
    public String testA() throws InterruptedException {
        return "------testA";
    }

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

(5)启动类上加@EnableDiscoveryClient

        (6)测试:

                启动Se

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值