- 引入依赖
<dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId> </dependency>
- yml添加配置
feign: sentinel: enabled: true
- 编写feign接口并配置fallback属性
@FeignClient(value = "nacos-client-app" , contextId = "nacosHelloClient" , fallback = NacosHelloClientFallback.class ) public interface NacosHelloClient { @GetMapping("/hello/index") String hello() ; @GetMapping("/hello/exception") String exception() ; }
- 编写fallback实现代码
@Component public class NacosHelloClientFallback implements NacosHelloClient { @Override public String hello() { return "fallback hello ret value"; } @Override public String exception() { return "fallback exception ret value"; } }
文章来源地址https://uudwc.com/A/Jw9BP
文章来源:https://uudwc.com/A/Jw9BP