1.添加熔断器依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
</dependency>
<!--hystrix依赖,主要是用 @HystrixCommand -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>
2.在调用端的配置文件中开启熔断器
#开启熔断机制
feign.hystrix.enabled=true
# 设置hystrix超时时间,默认1000ms
hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=6000
3.在使用nacos创建的interface之后创建它的实现类,在实现类中实现出错后输出的内容
@Component
public class VodFileDegradeFeignClient implements VodClient {
@Override
public R removeAliyunVideo(String id) {
return R.error().message("删除视频方法出错了");
}
@Override
public R removeMoreVideo(List<String> videoIdList) {
return R.error().message("删除多个视频方法出错了");
}
}
4.在interface上添加注解和属性
@FeignClient(name = "service-vod",fallback = VodFileDegradeFeignClient.class)