Sentinel基本使用
Sentinel 基本使用指南:快速集成与核心功能上手
Sentinel 作为轻量级的流量控制组件,集成过程简单高效,通过少量配置即可实现流量控制、熔断降级等核心功能。本文将详细介绍 Sentinel 在 Spring Cloud Alibaba 环境中的基本使用方法。
核心依赖集成
在 Spring Cloud 项目中,只需引入 Sentinel 的 starter 依赖即可快速集成:
<!-- Spring Cloud Alibaba Sentinel 核心依赖 -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
<!-- 版本需与Spring Cloud Alibaba版本匹配,如2.2.7.RELEASE -->
</dependency>
<!-- 可选:Actuator依赖,用于暴露Sentinel监控端点 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
spring-cloud-starter-alibaba-sentinel:包含 Sentinel 核心库和 Spring Cloud 集成逻辑;spring-boot-starter-actuator:可选依赖,用于通过/actuator/sentinel端点查看 Sentinel 规则和监控数据。
核心配置(application.yml)
通过配置文件指定 Sentinel 控制台地址及通信端口: