springcloud 利用hystrix服务降级出现问题

2021/9/6 23:36:41

本文主要是介绍springcloud 利用hystrix服务降级出现问题,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

com.netflix.hystrix.contrib.javanica.exception.FallbackDefinitionException: fallback method wasn't found: payment_Global_FallbackMethod([])

原因:

   配置全局兜底方法时,不需要参数。

  public  String   payment_Global_FallbackMethod(){
        return "全局兜底方法(*^▽^*)";
    }

服务降级方法:

   @HystrixCommand
   public    String paymentInfo_TimeOut(@PathVariable("id") Integer id){
       // int  age=10/0;
        return orderHyxtrixService.paymentInfo_TimeOut(id);
    }

我的原因是

  

public  String   payment_Global_FallbackMethod(@PathVariable("id") Integer id){
    return "全局兜底方法(*^▽^*)";
}

知识点:

 

/**
 * 消费者端服务降级
 *   解决问题
 *      服务端超时
 *      消费者出现问题
 *    准备工作:
 *        在yml配置文件中添加
 *            feifn:
 *             hyxtrix:
 *              enable: true
 *
 *         在主启动类上添加
 *                 @EnableHyxtrix
 *
 *         解决方法:
 *         通过@HystrixCommand 在出现异常中方法中添加,@HystrixCommand 指定当前方法出现问题时,将跳转兜底方法
 *     @HystrixCommand使用
  *        @HystrixCommand(fallbackMethod = "paymentInfo_TimeOutHandler",
  *        commandProperties = {@HystrixProperty(name="execution.isolation.thread.timeoutInMilliseconds",value="3000")})
  *        fallbackMethod:兜底方法名
 *
 *
 *        知识点二:
 *           问题:服务降级每个方法都添加hyxtrix兜底的方法,造成方法的膨胀
 *
 *           解决:
 *             //@DefaultProperties(defaultFallback ="")指定全局兜底方法,与注解@HystrixCommand配套使用,如果注解@HystrixCommand定义
 *             fallback方法,走自己定义的fallback方法,反之走@DefaultProperties中指定的方法


这篇关于springcloud 利用hystrix服务降级出现问题的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程