java timeout超时不抛异常_springCloud 请求超时解决方案 java.net.SocketTimeOut Exception: Read time out 异常解决...

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

例:app

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断路器的配置问题:

例如:code

http://www.itmuch.com/spring-cloud-feign-ribbon-first-request-fail/源码

经过使用屡次发现并非断路器的问题.博客

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

详细测试步骤参考:http://stackoverflow.com/questions/39154613/netflix-ribbon-and-hystrix-timeoutio

经过查找源码发现了以下的配置文件

源码定义以下

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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值