分享

springcloud 请求超时java.net.SocketTimeoutException: Read timed out异常解决.

 邵飞翔 2017-08-25

<1>通过日志发现 当控制层访问微服务的响应时间超过5秒

例:

2017-04-14 14:07:28.684  INFO 25898 --- [nio-8081-exec-2] com.zhongqi.controller.ApplyController   : 入库程序运行时间: 5192ms;

就会出现 :

Read timed out executing POST http://match-manager-apply/userApply/addUserCertificateList?matchId=9] with root cause

<2>通过查阅资料发现是很多博主都说是hystrix断路器的配置问题:
例如:

http://www./spring-cloud-feign-ribbon-first-request-fail/

通过使用多次发现并不是断路器的问题.

通过查阅博客:发现时ribbon的配置问题

详细测试步骤参考:http:///questions/39154613/netflix-ribbon-and-hystrix-timeout

通过查找源码发现了如下的配置文件

  • 源码定义如下

  • hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds:断路器的超时时间需要大于ribbon的超时时间,不然不会触发重试。

  • hello-service.ribbon.ConnectTimeout:请求连接的超时时间

  • hello-service.ribbon.ReadTimeout:请求处理的超时时间

  • hello-service.ribbon.OkToRetryOnAllOperations:对所有操作请求都进行重试

  • hello-service.ribbon.MaxAutoRetriesNextServer:切换实例的重试次数

  • hello-service.ribbon.MaxAutoRetries:对当前实例的重试次数

在控制层 配置文件:application.properties

添加

hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=6000
spring.cloud.loadbalancer.retry.enabled=true
ribbon.ReadTimeout=60000
ribbon.ConnectTimeout=60000

就可以解决访问超时的问题。

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多