feign负载eureka中添加hystrix模块的坑

从坑中爬出来做个标记
我用的cloud版本是Greenwich.SR1

模仿的环境是
customer 调用 provider 超时或异常后走hystrix模块
上配置

feign:
  hystrix:
    enabled: true ##此处非常重要
  client:
    config:
      default:  #customer instanceId
        connectTimeout: 5000 
        readTimeout: 5000  ##读取5秒超时
eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:8888/eureka/
    ## 是否注册自己
    register-with-eureka: false
    ## 检索注册服务
    fetch-registry: true
  instance:
    prefer-ip-address: true

配置完成后报错如下:
第一部分:
019-06-26 15:59:34.161 ERROR 11728 — [ HystrixTimer-1] com.gd.test.services.FeignHelloService : hello error
com.netflix.hystrix.exception.HystrixTimeoutException: null
at com.netflix.hystrix.AbstractCommand$HystrixObservableTimeoutOperator$1.run(AbstractCommand.java:1142) ~[hystrix-core-1.5.18.jar:1.5.18]
at com.netflix.hystrix.strategy.concurrency.HystrixContextRunnable$1.call(HystrixContextRunnable.java:41) ~[hystrix-core-1.5.18.jar:1.5.18]
at com.netflix.hystrix.strategy.concurrency.HystrixContextRunnable$1.call(HystrixContextRunnable.java:37) ~[hystrix-core-1.5.18.jar:1.5.18]
第二部分:
2019-06-26 15:59:35.835 ERROR 11728 — [trix-customer-1] c.n.d.s.t.d.RedirectingEurekaHttpClient : Request execution error. endpoint=DefaultEndpoint{ serviceUrl='http://localhost:8888/eureka/}
com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server
com.netflix.client.ClientException: Load balancer does not have available server for client:

如果吧配置改成

feign:
  hystrix:
    enabled: false 

启动工程,正常。

考虑是HystrixTimeoutException导致的后续错误查阅文档如下:
https://github.com/Netflix/Hystrix/wiki/Configuration#execution.isolation.thread.timeoutInMilliseconds
execution.isolation.thread.timeoutInMilliseconds 默认1秒
添加配置组织hystrix自己的超时

hystrix:
  command:
    default:
      execution:
        timeout:
          enabled: false

直接禁用,启动后正常

如果hystrix自己有超时调用服务还有超时 ,太复杂啦。直接处理调用服务的超时感觉合理点。

不然这么多超时时间。如果配错一个就会导致服务问题,感觉这种超时配置越少越少

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值