问题介绍: 服务之间调用报错超时( 读取超时时间长 ),截取部分报错,Read timed out executing POST http://****** , Feign底层使用Ribbon调用请求,ribbon的默认超时时间为1s,所以超过1s没有数据返回就会报错
原因及解决办法:
明显可以看到是http请求报错超时,feign的调用分两层,ribbon的调用和hystrix的调用,高版本的hystrix默认是关闭的,所以在application.properties配置文件中设置ribbon即可
ribbon:
ReadTimeout: 60000 #请求处理的超时时间(建立连接后从服务器读取到可用资源所用的时间)
ConnectTimeout: 60000 #请求连接的超时时间,默认时间为1秒
eureka:
enable: true
如果开启hystrix,hystrix的超时报错如下图: FeignDemo#demo() timed-out and no fallback available。和ribbon超时报错还是有区别的
com.netflix.hystrix.exception.HystrixRuntimeException: FeignDemo#demo() timed-out and no fallback available.
at com.netflix.hystrix.AbstractCommand$22.call(AbstractCommand.java:819)
at com.netflix.hystrix.AbstractCommand$22.call(AbstractCommand.java:804)
at rx.internal.operators.OperatorOnErrorResumeNextViaFunction$4.onError(OperatorOnErrorResumeNextViaFunction.java:140)
at rx.internal.operators.OnSubscribeDoOnEach$DoOnEachSubscriber.onError(OnSubscribeDoOnEach.java:87)
at rx.internal.operators.OnSubscribeDoOnEach$DoOnEachSubscriber.onError(OnSubscribeDoOnEach.java:87)
at com.netflix.hystrix.AbstractCommand$DeprecatedOnFallbackHookApplication$1.onError(AbstractCommand.java:1472)
at com.netflix.hystrix.AbstractCommand$FallbackHookApplication$1.onError(AbstractCommand.java:1397)
at rx.internal.operators.OnSubscribeDoOnEach$DoOnEachSubscriber.onError(OnSubscribeDoOnEach.java:87)
at rx.observers.Subscribers$5.onError(Subscribers.java:230)
Caused by: java.util.concurrent.TimeoutException
at com.netflix.hystrix.AbstractCommand.handleTimeoutViaFallback(AbstractCommand.java:997)
at com.netflix.hystrix.AbstractCommand.access$500(AbstractCommand.java:60)
at com.netflix.hystrix.AbstractCommand$12.call(AbstractCommand.java:610)
at com.netflix.hystrix.AbstractCommand$12.call(AbstractCommand.java:601)
解决办法:
feign.hystrix.enabled: true
#hystrix 熔断机制
hystrix:
shareSecurityContext: true
command:
default:
circuitBreaker:
sleepWindowInMilliseconds: 100000
forceClosed: true
execution:
isolation:
thread:
timeoutInMilliseconds: 600000
#mst默认配置
#Feign客户端的建立连接的最长等待时间,单位为毫秒, 默认值为10000毫秒(10秒)。
feign.client.config.default.connectTimeout=5000
#Feign客户端从服务端读取数据的最长等待时间,单位为毫秒, 默认值为60000毫秒(60秒)
feign.client.config.default.readTimeout=5000#Hystrix命令的执行超时时间,即Hystrix命令的最长执行时间,单位为毫秒, 默认值为1000毫秒(1秒)。
hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=5000
# ribbon服务列表刷新时间(Ribbon服务列表刷新的间隔时间,即Ribbon定期从服务注册中心获取最新的服务列表的时间间隔,单位为毫秒。)
ribbon.ServerListRefreshInterval=1000
# ibbon请求连接的超时时间,即Ribbon建立与服务提供者的连接的最长等待时间,单位为毫秒, 默认值为1000毫秒(1秒)
ribbon.ConnectTimeout=30000
# Ribbon请求处理的超时时间,即Ribbon从服务提供者读取数据的最长等待时间,单位为毫秒, 默认值为1000毫秒(1秒)
ribbon.ReadTimeout=30000# Hystrix线程池的最大线程数,即Hystrix线程池可以容纳的最大线程数量, 默认值为10。
hystrix.threadpool.default.maximumSize=80
#Hystrix线程池的核心线程数,即Hystrix线程池中始终保持活动状态的最小线程数量, 默认值为10。
hystrix.threadpool.default.coreSize=40# OpenFeign线程池配置(zeekr没有使用hystrix, 使用了以下配置) feign: threadpool: default: # 核心线程数 coreSize: 80 # 最大线程数 maximumSize: 40
原文: spring cloud 调用feign请求超时 feign.RetryableException: Read timed out executing POST-优快云博客