从坑中爬出来做个标记
我用的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自己有超时调用服务还有超时 ,太复杂啦。直接处理调用服务的超时感觉合理点。
不然这么多超时时间。如果配错一个就会导致服务问题,感觉这种超时配置越少越少