通过整合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 { .... }