通过整合sentinel实现Feign调用服务,当调用出错后实现容错降级。
1、引入pom
<!--sentinel客户端--> <dependency> <groupId>com.alibaba.cloud</groupId> <
artifactId>spring-cloud-starter-alibaba-sentinel</artifactId> </dependency>
2、配置yaml
# feign启用sentinel feign: sentinel: enabled: true
2、创建Fallback容错类
@Component public class TestServiceFallbackFactory implements FallbackFactory<
TestFeign> { @Override public WageServiceFeign create(Throwable throwable) { //
可以将异常继续抛出,也可以实现自定义的内容 throw new RuntimeException(throwable.getMessage()); } }
修改@FeignClient
//加入fallbackFactory指向容错类 @FeignClient(value = "b-service",fallbackFactory =
TestServiceFallbackFactory.class)) public interface TestFeign { .... }

技术
今日推荐
PPT
阅读数 121
下载桌面版
GitHub
百度网盘(提取码:draw)
Gitee
云服务器优惠
阿里云优惠券
腾讯云优惠券
华为云优惠券
站点信息
问题反馈
邮箱:ixiaoyang8@qq.com
QQ群:766591547
关注微信