feign.RetryableException: Read timed out executing xxx

博客介绍了Spring Cloud中服务间调用Feign请求超时的问题,指出Feign底层用Ribbon调用,默认超时时间为1s。分析了feign调用分ribbon和hystrix两层,高版本hystrix默认关闭,给出在application.properties配置文件中设置相关超时时间的解决办法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

问题介绍: 服务之间调用报错超时( 读取超时时间长 ),截取部分报错,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-优快云博客

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值