需要安装sentinel
https://github.com/alibaba/Sentinel/releases/download/1.6.3/sentinel-dashboard-1.6.3.jar
pom.xml
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
</dependency>
server:
port: 8401
spring:
application:
name: cloudalibaba-sentinel-service
cloud:
nacos:
discovery:
server-addr: localhost:8848 #Nacos服务注册中心地址
sentinel:
transport:
dashboard: localhost:8080 #配置Sentinel dashboard地址
port: 8719
datasource:
ds1:
nacos:
server-addr: localhost:8848
dataId: ${spring.application.name}
groupId: DEFAULT_GROUP
data-type: json
rule-type: flow
management:
endpoints:
web:
exposure:
include: '*'
不需要在启动类上加注解
用@sentinelResource(value=”fallback” fallback=”handlerFallback”)
blockHandler只负责控制台配置违规,也就是说如果设置了调用次数,那超出调用次数就执行blockHandler设置的方法
如果有业务违规和控制台配置的参数超过,那会执行blockHandler设置的方法
feing 集成 sentinel: