Sentinel
Sentinel前期准备
- 下载地址:
https://github.com/alibaba/Sentinel/releases
注意:要下载Jar包
- 在sentinel的jar目录下cmd执行如下命令:
java -Dserver.port=8180 -Dcsp.sentinel.dashboard.server=localhost:8180 -Dproject.name=sentinel-dashboard -jar sentinel-dashboard-1.8.1.jar
**注意:**根据自己的jar版本号执行命令
- 访问Sentinal服务
默认网址:
http://localhost:8180
默认账户和密码:sentinel

一. Sentinel限流入门
1. 添加依赖
<!--sentinel依赖,添加了此依赖以后,会在项目中添加一个拦截器对象,这个对象会对
向此服务发出的请求,进行拦截,拦截到请求以后会与sentinel控制台定义的限流规则进行比对,
假如在允许范围之内,则继续访问,否则进行限流或降级等操作-->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
</dependency>
2.修改配置文件
- 在提供方添加配置
spring:
cloud:
sentinel:
transport:
dashboard: localhost:8180 #这里描述的n是sentinel控制台的地址
eager: true #服务启动以后,就会sentinel控制台发送一个心跳消息
3.创建限流操作的Controller对象
- 在提供方添加
package com.jt.provider.controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/provider")
public class ProviderSentinelController {
@GetMapping("/sentinel01")
public

本文介绍了如何在Spring项目中集成Sentinel,包括添加依赖、配置限流规则、设置流控模式、链路限流、编写降级策略和使用拦截器实现异常处理。此外,还涵盖了热点数据限流、系统规则应用及授权规则的实战步骤。
最低0.47元/天 解锁文章

被折叠的 条评论
为什么被折叠?



