1,sentinel服务器下载配置启动
2,添加依赖
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-sentinel-gateway</artifactId>
</dependency>
3,配置
sentinel:
transport:
dashboard: 127.0.0.1:8888
eager: true
scg: #自定义限流返回结果
fallback:
# mode: redirect
# redirect: https://www.baidu.com
mode: response
response-status: 426
response-body: '{"code": 426,"message": "限流了,稍后重试!"}'
4,服务之间调用降级,feign使用sentinel
feign:
sentinel:
enabled: true
使用fallback和fallbackFactory