使用feign和hystrix报错timed-out and no fallback

在服务消费端使用feign和hystrix做熔断处理时,报错timed-out and no fallback,造成该错误的原因是:服务连接正常,读取回调数据异常。

解决方案:

      这种情况是hystrix没有起作用,通过配置文件指定超时时间hystrix.command.userGetKey.execution.isolation.thread.timeoutInMilliseconds = 13000

或者通过注解的形式@HystrixCommand(fallbackMethod="fallback", commandProperties = { @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "1000" ) } ),而且一定要注意要开启hystrix的效果:在主启动类加上注解@EnableCircuitBreaker

 

       还有一个小细节要注意就是在服务消费端同时使用feign和hystrix时,feign有一个默认的连接超时时间1秒钟,想要不影响hystrix的正常熔断功能,需要:

ribbon:

    connectTimeout:4000 # 建立网络连接时间    

    redTimeout:4000 # 建立连接后读取资源所用时间

连接时间大于hystrix的超时时间即可 ,或者

feign:

   hystrix:

       enabled:true # 开启hystrix

 

posted @ 2020-08-12 22:57  River*  阅读(1409)  评论(0)    收藏  举报