1. pom中添加依赖

    1. <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-hystrix</artifactId>
      <version>1.4.6.RELEASE</version>
      </dependency>

  2. 在配置文件中添加hystrix配置

    1.   
      feign.hystrix.enabled=true

      hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=6000
  3. 在service-edu的client包里面创建熔断器的实现类

    1. @Component
      public class VodFileDegradeFeignClient implements VodClient{
      @Override
      public R removeALYVideo(String id) {
      return R.error().message("删除视频出差错了");
      }

      @Override
      public R deleteBatch(List<String> videoIdList) {
      return R.error().message("删除多个视频出差错了");
      }
      }
  4. 修改VodClient接口的注解

    1.   
      @Component
      @FeignClient(name = "service-vod1",fallback = VodFileDegradeFeignClient.class)
      public interface VodClient {
      @DeleteMapping("/vod/video/delete/{id}")
      public R removeALYVideo(@PathVariable("id") String id);

      @DeleteMapping("/vod/video/delete-batch")
      public R deleteBatch(@RequestParam("videoIdList") List<String> videoIdList);


      }

 

 

 

 

  

 

posted on 2021-06-03 16:22  upupup-999  阅读(41)  评论(0)    收藏  举报