我有一个 zuul 服务器,配置文件为:
server:
port: 9090
eureka:
client:
serviceUrl:
defaultZone: http://172.16.5.147:8761/eureka/
instance:
leaseRenewalIntervalInSeconds: 30
hostname: dev-zuulserver
non-secure-port: 80
zuul:
prefix: /v1
sensitiveHeaders: Cookie, Set-Cookie
ignoredHeaders: Access-Control-Allow-Origin
host:
connect-timeout-millis: 60000 # starting the connection
socket-timeout-millis: 120000 # monitor the continuous incoming data flow
ribbon:
eureka:
enabled: true
ReadTimeout: 120000
ConnectTimeout: 3000
hystrix:
command:
default:
execution:
isolation:
strategy: THREAD
thread:
timeoutInMilliseconds: 60000
我有一些超时更长(超过一分钟(的查询。但是,我的所有请求总是因超时而出错,请求时间始终小于 6000 毫秒。
zuul 显示此例外:
由以下原因引起:java.lang.Runtime异常:java.net.SocketTimeout异常:读取超时
at rx.exceptions.Exceptions.propagate(Exceptions.java:58( ~[rxjava-1.1.10.jar!/:1.1.10]
at rx.observables.BlockingObservable.blockForSingle(BlockingObservable.java:465( ~[rxjava-1.1.10.jar!/:1.1.10] at rx.observables.BlockingObservable.single(BlockingObservable.java:342( ~[rxjava-1.1.10.jar!/:1.1.10] at com.netflix.client.AbstractLoadBalancerAwareClient.executeWithLoadBalancer(AbstractLoadBalancerAwareClient.java:117( ~[ribbon-loadbalancer-2.2.2.jar!/:2.2.2] ...省略 133 个常见帧 原因:java.net.SocketTimeout异常:读取超时 at java.net.SocketInputStream.socketRead0(Native Method( ~[na:1.8.0_131] at java.net.SocketInputStream.socketRead(SocketInputStream.java:116( ~[na:1.8.0_131] at java.net.SocketInputStream.read(SocketInputStream.java:171( ~[na:1.8.0_131] at java.net.SocketInputStream.read(SocketInputStream.java:141( ~[na:1.8.0_131] at org.apache.http.impl.io.SessionInputBufferImpl.streamRead(SessionInputBufferImpl.java:137( ~[httpcore-4.4.6.jar!/:4.4.6] at org.apache.http.impl.io.SessionInputBufferImpl.fillBuffer(SessionInputBufferImpl.java:153( ~[httpcore-4.4.6.jar!/:4.4.6] at org.apache.http.impl.io.SessionInputBufferImpl.readLine(SessionInputBufferImpl.java:282( ~[httpcore-4.4.6.jar!/:4.4.6] at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:138( ~[httpclient-4.5.3.jar!/:4.5.3] at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:56( ~[httpclient-4.5.3.jar!/:4.5.3] at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:259( ~[httpcore-4.4.6.jar!/:4.4.6] at org.apache.http.impl.DefaultBHttpClientConnection.receiveResponseHeader(DefaultBHttpClientConnection.java:163( ~[httpcore-4.4.6.jar!/:4.4.6] at org.apache.http.impl.conn.CPoolProxy.receiveResponseHeader(CPoolProxy.java:165( ~[httpclient-4.5.3.jar!/:4.5.3] at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:273( ~[httpcore-4.4.6.jar!/:4.4.6] at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:125( ~[httpcore-4.4.6.jar!/:4.4.6]
有人有这种情况的解决方案吗?
谢谢!
尝试在 ZUUL 配置中添加功能区超时。
以下将设置2分钟的超时。
ribbon:
ConnectTimeout: 120000
ReadTimeout: 120000
在你的应用程序中,属性只需添加:
hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds: 240000
ribbon.ConnectTimeout: 120000
ribbon.ReadTimeout: 120000