Sentinel 学习笔记

Sentinel

Alibaba Sentinel 官方文档地址: https://github.com/alibaba/Sentinel/wiki/%E4%BB%8B%E7%BB%8D

Sentinel使用:
1. 在pom.xml文件中加入依赖,根据所依赖的Spring Cloud及Spring Cloud Alibaba版本决定sentinel使用哪个版本,以下版本对应Spring Cloud Alibaba2.1.0.RELESE版本,对应Spring Cloud Greenwich.SR2版本

  <dependency>
        <groupId>com.alibaba.cloud</groupId>
        <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
        <version>2.1.0.RELEASE</version>
    </dependency>

加入以上依赖后,可通过http://localhost:port/actuator/sentinel 查看是否配置成功,若请求地址有返回信息,则说明Sentinel配置成功(若想使用actuator,须加入actuator依赖)
actuator依赖:
a

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

在appcation.yml 配置

    management:
        endpoints:
            web:
                exposure:
                    include: '*'

请求http://localhost:port/actuator/sentinel 返回信息:
在这里插入图片描述
2.在配置文件中(application.yml/bootstrap.yml)中添加配置 ,以下配置为sentiel 控制台配置地址

 spring: 
 	application:
		name: XXXX(服务名称)
	cloud: 
  		 sentinel: 
    		 transport: 
 				# 指定sentinel 控制台地址
				dashboard: 127.0.0.1:8080

3.使用Sentinel 控制台
前往官方GitHub上下载Sentinel 控制台jar包
地址: https://github.com/alibaba/Sentinel/releases
根据自己项目中所使用的Sentinel 版本下载对应的jar包版本,在IDE中可进行查看所使用的Sentinel版本。
在这里插入图片描述
将下载下来的Sentinel控制台jar包通过java -jar 方式执行
在这里插入图片描述
启动成功后,访问 http://localhost:8080,即可打开Sentinel 控制台,账号密码默认为:sentinel/sentinel
在这里插入图片描述
再启动配置好Sentinel 的工程(服务),任意访问一个接口,再刷新控制台,即可查看到对应工程(服务)相应的接口,并可对接口进行限流、降级操作。,任意访问一个接口,再刷新控制台,即可查看到对应工程(服务)相应的接口,并可对接口进行限流、降级操作。
具体使用规则,可查看官方文档说明,以下总结几个使用方式
Sentinel 使用方式,具体详情可查看官方文档。
这里推荐一个大佬的手记文档:
SentinelResource注解 属性总结 :https://www.imooc.com/article/289384
Alibaba Sentinel 规则参数总结:https://www.imooc.com/article/289345
Alibaba Sentinel 配置项总结: https://www.imooc.com/article/289562

使用方式使用方式使用方法
编码方式APItry…catch…finally
注解方式SentinelResourceblockHandler/fallback
RestTemplateSentinelRestTemplateblockHandler/fallback
Feignfeign.sentinel.enabled=truefallback/fallbackFactory

生产环境使用Sentinel 规则持久化有以下三种方法,根据实际项目选择合适的即可。
方式一:
Alibaba Sentinel 拉模式
具体操作可参考这篇文章: https://www.imooc.com/article/289402
方式二:
Alibaba Sentinel 推模式
具体操作可参考这篇文章: https://www.imooc.com/article/289464
方式三:
Alibaba Sentinel 推出的Sentinel 在线托管Sentinel 控制台AHAS
开通地址: https://ahas.console.aliyun.com/
使用说明: https://help.aliyun.com/document_detail/110599.html?spm=a2c4g.11186623.6.597.74dc4ac5lz0dWn

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值