SpringCloud Feign对Hystrix(断路由)的支持

第一步:首先开启Feign对Hystrix的支持,在yml文件中添加以下配置:

feign:

  hystrix:

      enabled=true.                           //false表示禁用Hystrix

第二步:在Feign的基础上添加Hystrix(断路由)

@FeignClient(name = "这里写需要调用服务名称  serviceName",fallback = "XxxServiceHystrix.class")
public interface XxxServiceAPI {

@RequestMapping(value = "/Xxx/getXxxInfo", method = RequestMethod.GET)
public BaseResponse<XxxxInfo> getXxxInfo(@RequestParam("Id")  Integer Id);

第三步:编写XxxServiceHystrix类(断路器类的方法需要和远API方法一致[参数   结果集])

@Component

public class XxxServiceHystrix implement XxxServiceAPI{

  @Override

  public BaseResponse<XxxInfo> getXxxInfo(Integer Id){

    return new BaseResponse<>().fail("调用服务失败");

  }

}


//在启动类加上注解:

@EnableFeignClient

SpringCloud Feign对Hystrix(断路由)的支持

测试步骤:把你需要调用的服务(serviceName)挂掉,使用Feign调用服务,如果返回 “调用服务失败“ 则Hystrix(断路由)生效

相关文章:

  • 2022-12-23
  • 2021-12-08
  • 2022-12-23
  • 2021-07-30
  • 2021-04-04
猜你喜欢
  • 2021-05-17
  • 2022-12-23
  • 2022-03-08
  • 2021-11-25
  • 2021-10-27
  • 2021-05-18
相关资源
相似解决方案