Spring Cloud 核心组件 Sentinel
- 作者:DecaMinCow
- 博客:http://blog.csdn.net/m0_37567301
- 邮箱:decamincow#gmail.com (#->@)
Sentinel 介绍
Sentinel 是一个面向云原生微服务的流量控制、熔断降级组件
本人推荐用此组件,因为代码侵入低,适合云原生微服务
https://github.com/alibaba/Sentinel/releases
Sentinel 特征
- 丰富的应用场景:Sentinel 承接了阿里巴巴近 10 年的双十一大促流量的核心场景,例如秒杀(即 突发流量控制在系统容量可以承受的范围)、消息削峰填谷、集群流量控制、实时熔断下游不可用 应用等。
- 完备的实时监控:Sentinel 同时提供实时的监控功能。您可以在控制台中看到接入应用的单台机器 秒级数据,甚至 500 台以下规模的集群的汇总运行情况。
- 广泛的开源生态:Sentinel 提供开箱即用的与其它开源框架/库的整合模块,例如与 Spring Cloud、Dubbo的整合。您只需要引入相应的依赖并进行简单的配置即可快速地接入 Sentinel。
- 完善的 SPI 扩展点:Sentinel 提供简单易用、完善的 SPI 扩展接口。您可以通过实现扩展接口来快 速地定制逻辑。例如定制规则管理、适配动态数据源等。
启动服务
java -jar sentinel-dashboard-1.7.2.jar &
访问 dashboard 后台
# 账号/密码 sentinel/sentinel
http://localhost:8080
相关依赖
<!--SCA -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
<version>2.1.0.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
</dependency>
<!-- Sentinel支持采用 Nacos 作为规则配置数据源,引入该适配依赖 -->
<dependency>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-datasource-nacos</artifactId>
</dependency>
nacos 配置
# 配置限流规则
# DATA ID = {application.name}-flow-rules
# 配置 JSON 格式
[{
"resource":"findResumeOpenState",
"limitApp":"default",
"grade":1,
"count":1,
"strategy":0,
"controlBehavior":0,
"clusterMode":false
}]
# 配置降级规则
# DATA ID = {application.name}-degrade-rules
# 配置 JSON 格式
[{
"resource":"findResumeOpenState",
"grade":2,
"count":1,
"timeWindow":5
}]