Through integration sentinel realization Feign Call service , Fault tolerant degradation is realized when the call fails .
1, introduce pom
<!--sentinel client --> <dependency> <groupId>com.alibaba.cloud</groupId> <
artifactId>spring-cloud-starter-alibaba-sentinel</artifactId> </dependency>
2, to configure yaml
# feign Enable sentinel feign: sentinel: enabled: true
2, establish Fallback Fault tolerant class
@Component public class TestServiceFallbackFactory implements FallbackFactory<
TestFeign> { @Override public WageServiceFeign create(Throwable throwable) { //
You can continue to throw exceptions , You can also implement customized content throw new RuntimeException(throwable.getMessage()); } }
modify @FeignClient
// join fallbackFactory Point to fault tolerance class @FeignClient(value = "b-service",fallbackFactory =
TestServiceFallbackFactory.class)) public interface TestFeign { .... }

Technology