1、引入依赖
nacos-consumer模块引入feign及sentinel的依赖
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
2、开启sentinel监控功能
feign:
sentinel:
enabled: true
3、代码实现
(1)添加feign接口的熔断类ProviderFallback:
@Component
public class ProviderFallback implements ProviderClient {
@Override
public String hello() {
return "现在服务器忙,请稍后再试!";
}
}