本地搭建Sentinel
构建springboot项目
引入sentinel-core依赖
在pom.xml中引入sentinel-core的依赖
<dependency>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-core</artifactId>
<version>1.8.0</version>
</dependency>
编写代码
-
定义限流规则
限流规则分四步:- 创建存放限流规则的集合
- 创建限流规则
- 将限流规则存放到集合中
- 加载限流规则
具体代码实现如下:
//定义限流规则 //@PostConstruct 当前类的构造函数执行之后执行有该注解的方法 @PostConstruct public void i