09 springcloud的熔断器.png
一、添加依赖
<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>
二、创建实现类,在发生熔断之后进行什么操作
public class VodClientFeginImpl implements VodClient{
@Override
public R deleteVideoById(String id) {
return R.error().message("删除视频失败");
}
@Override
public R deleteVideoes(List<String> videoList) {
return R.error().message("批量删除视频失败");
}
}
三、在interface上添加注解和属性
@FeignClient(name = "service-vod",fallback = VodClientFeginImpl.class)//调用服务的名称
@Component
public interface VodClient {
//PathVariable注解一定要指定参数名称,否则出错
@DeleteMapping("/eduvod/vod/deleteVideo/{id}")//必须是全路径
public R deleteVideoById(@PathVariable("id") String id);
//删除多个视频的方法
@DeleteMapping("/eduvod/vod/delete-batch")
public R deleteVideoes(@RequestParam("videoList") List<String> videoList);
}
网友评论