1添加依赖
<!--hystrix依赖,主要是用 @HystrixCommand -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>
2.添加hystrix配置
#开启熔断机制
feign.hystrix.enabled=true
# 设置hystrix超时时间,默认1000ms
hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=6000
3.创建一个实现类如果出错执行对应的方法
@Component
public class VodFileDegradeFeignClient implements VodClient{
@Override
public R deleteAlyiVideo(String videoId) {
return R.Error().message("删除视频出错了");
}
@Override
public R delete_bantch(List<String> videolist) {
return R.Error().message("删除多个视频出错了");
}
}
4.更改注解
@FeignClient(name="service-vod",fallback =VodFileDegradeFeignClient.class)
@Component
public interface VodClient {
//定义调用方法的路径
@DeleteMapping("/eduvod/video/deleteAlyiVideo/{videoId}")
public R deleteAlyiVideo(@PathVariable("videoId") String videoId);
//定义调用删除多个视频方法的路径
//删除多个视频
@DeleteMapping("/eduvod/video/delete-bantch")
public R delete_bantch(List<String> videolist);
}