在 Spring TCP 集成的 TcpOutboundGateway 等待响应异常超时
Timed out waiting for response exception at TcpOutboundGateway at Spring TCP Integration
目前我正在通过 Spring Integration TCP
进行外部供应商集成,我正在发送到 2 个 IP 的不同端口(IP 1、端口 1、2、3 和 IP 2 端口 1、2 和 3)通过为独特的 IP/Port 组合创建不同的 @ServiceActivator
。
在正常消息负载下一切正常,但是,当我将负载增加到 40-50 transactions/sec 时,我看到消息因等待响应而超时。
下面是其中一个服务激活器,其他的也以类似的方式设置。如果我的主 IP 不可用,我将使用 FailoverClientConnectionFactory
进行故障转移。我也在使用 CachingClientConnectionFactory
,这样每个请求我都不必创建一个昂贵的连接。
@Bean
@ServiceActivator(inputChannel = "toRequest")
public MessageHandler serviceActivatorOne() {
TcpOutboundGateway tcpOutputGateway = new TcpOutboundGateway();
List<ServerNode> nodes = properties.getFailOver().getServers().subList(0,2);
tcpOutputGateway.setConnectionFactory(createFailOverConnectionFactory(nodes));
tcpOutputGateway.setReplyChannelName("bytesToObjectChannel");
tcpOutputGateway.setRemoteTimeout(5000);
return tcpOutputGateway;
}
...
...
private AbstractClientConnectionFactory createFailOverConnectionFactory(List<ServerNode> serverNodeList) {
FailoverClientConnectionFactory connectionFactory =
new FailoverClientConnectionFactory(createConnectionFactories(serverNodeList));
connectionFactory.setSingleUse(true);
connectionFactory.afterPropertiesSet();
return connectionFactory;
}
private AbstractClientConnectionFactory createDefaultConnectionFactory(String url, int port, String name) {
TcpNetClientConnectionFactory connFactory = new TcpNetClientConnectionFactory(url, port);
connFactory.setSerializer(byteArrayLengthHeaderSerializer());
connFactory.setDeserializer(byteArrayLengthHeaderSerializer());
connFactory.setSoTimeout(properties.getSocketTimeOut());
connFactory.setSoKeepAlive(true);
connFactory.setLookupHost(false);
connFactory.setComponentName(name);
connFactory.setSingleUse(true);
if(properties.getPoolMaxSize() <= 0) {
return connFactory;
} else {
CachingClientConnectionFactory cachingConnFactory =
new CachingClientConnectionFactory(connFactory, properties.getPoolMaxSize());
cachingConnFactory.setConnectionWaitTimeout(properties.getPoolMaxWait());
return cachingConnFactory;
}
}
异常详情:
[DEBUG]-[http-nio-9090-exec-103]-[11-Nov-2019;22:01:14.403]-[TcpOutboundGateway:handleRequestMessage:162]-Remote Timeout on 1980e8d4-3167-4610-b8ac-8fb0d20eb92a:1
[DEBUG]-[http-nio-9090-exec-103]-[11-Nov-2019;22:01:14.403]-[SimplePool:releaseItem:226]-Releasing TcpNetConnection:216.76.27.251:20303:54340:d9c78e03-ecbb-45af-b502-6aff9a9b0036 back to the pool
[ERROR]-[http-nio-9090-exec-103]-[11-Nov-2019;22:01:14.404]-[TcpOutboundGateway:handleRequestMessage:174]-Tcp Gateway exception
org.springframework.integration.MessageTimeoutException: Timed out waiting for response
at org.springframework.integration.ip.tcp.TcpOutboundGateway.handleRequestMessage(TcpOutboundGateway.java:166)
at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleMessageInternal(AbstractReplyProducingMessageHandler.java:123)
at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:162)
at org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:144)
at org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:105)
at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:73)
at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:453)
at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:401)
at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:187)
at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:166)
at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:47)
at org.springframework.messaging.core.AbstractMessageSendingTemplate.send(AbstractMessageSendingTemplate.java:109)
at org.springframework.integration.handler.AbstractMessageProducingHandler.sendOutput(AbstractMessageProducingHandler.java:4
我试图从 Spring TCP 参考资料中找出一些细节,但到目前为止没有成功。我没有使用共享套接字,因为 setSingleUse
设置为 false
。任何 help/clue 表示赞赏。
看起来您连接的服务器在高负载下无法及时响应 5 秒超时。
It seems the default remoteTimeout is 10s and I am setting to 5s which seems the server can't response with in 5s. I can tune the remoteTimeout and check. Do you have any suggestions where I can change any of the spring-tcp integration settings or is it solely depends on slow responsive nature from the server?
对,这确实取决于服务器。我想象一种情况,即使那 10 秒也不够,负载很大。您应该咨询您的服务器供应商以确定他们的吞吐量。
目前我正在通过 Spring Integration TCP
进行外部供应商集成,我正在发送到 2 个 IP 的不同端口(IP 1、端口 1、2、3 和 IP 2 端口 1、2 和 3)通过为独特的 IP/Port 组合创建不同的 @ServiceActivator
。
在正常消息负载下一切正常,但是,当我将负载增加到 40-50 transactions/sec 时,我看到消息因等待响应而超时。
下面是其中一个服务激活器,其他的也以类似的方式设置。如果我的主 IP 不可用,我将使用 FailoverClientConnectionFactory
进行故障转移。我也在使用 CachingClientConnectionFactory
,这样每个请求我都不必创建一个昂贵的连接。
@Bean
@ServiceActivator(inputChannel = "toRequest")
public MessageHandler serviceActivatorOne() {
TcpOutboundGateway tcpOutputGateway = new TcpOutboundGateway();
List<ServerNode> nodes = properties.getFailOver().getServers().subList(0,2);
tcpOutputGateway.setConnectionFactory(createFailOverConnectionFactory(nodes));
tcpOutputGateway.setReplyChannelName("bytesToObjectChannel");
tcpOutputGateway.setRemoteTimeout(5000);
return tcpOutputGateway;
}
...
...
private AbstractClientConnectionFactory createFailOverConnectionFactory(List<ServerNode> serverNodeList) {
FailoverClientConnectionFactory connectionFactory =
new FailoverClientConnectionFactory(createConnectionFactories(serverNodeList));
connectionFactory.setSingleUse(true);
connectionFactory.afterPropertiesSet();
return connectionFactory;
}
private AbstractClientConnectionFactory createDefaultConnectionFactory(String url, int port, String name) {
TcpNetClientConnectionFactory connFactory = new TcpNetClientConnectionFactory(url, port);
connFactory.setSerializer(byteArrayLengthHeaderSerializer());
connFactory.setDeserializer(byteArrayLengthHeaderSerializer());
connFactory.setSoTimeout(properties.getSocketTimeOut());
connFactory.setSoKeepAlive(true);
connFactory.setLookupHost(false);
connFactory.setComponentName(name);
connFactory.setSingleUse(true);
if(properties.getPoolMaxSize() <= 0) {
return connFactory;
} else {
CachingClientConnectionFactory cachingConnFactory =
new CachingClientConnectionFactory(connFactory, properties.getPoolMaxSize());
cachingConnFactory.setConnectionWaitTimeout(properties.getPoolMaxWait());
return cachingConnFactory;
}
}
异常详情:
[DEBUG]-[http-nio-9090-exec-103]-[11-Nov-2019;22:01:14.403]-[TcpOutboundGateway:handleRequestMessage:162]-Remote Timeout on 1980e8d4-3167-4610-b8ac-8fb0d20eb92a:1
[DEBUG]-[http-nio-9090-exec-103]-[11-Nov-2019;22:01:14.403]-[SimplePool:releaseItem:226]-Releasing TcpNetConnection:216.76.27.251:20303:54340:d9c78e03-ecbb-45af-b502-6aff9a9b0036 back to the pool
[ERROR]-[http-nio-9090-exec-103]-[11-Nov-2019;22:01:14.404]-[TcpOutboundGateway:handleRequestMessage:174]-Tcp Gateway exception
org.springframework.integration.MessageTimeoutException: Timed out waiting for response
at org.springframework.integration.ip.tcp.TcpOutboundGateway.handleRequestMessage(TcpOutboundGateway.java:166)
at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleMessageInternal(AbstractReplyProducingMessageHandler.java:123)
at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:162)
at org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:144)
at org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:105)
at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:73)
at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:453)
at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:401)
at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:187)
at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:166)
at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:47)
at org.springframework.messaging.core.AbstractMessageSendingTemplate.send(AbstractMessageSendingTemplate.java:109)
at org.springframework.integration.handler.AbstractMessageProducingHandler.sendOutput(AbstractMessageProducingHandler.java:4
我试图从 Spring TCP 参考资料中找出一些细节,但到目前为止没有成功。我没有使用共享套接字,因为 setSingleUse
设置为 false
。任何 help/clue 表示赞赏。
看起来您连接的服务器在高负载下无法及时响应 5 秒超时。
It seems the default remoteTimeout is 10s and I am setting to 5s which seems the server can't response with in 5s. I can tune the remoteTimeout and check. Do you have any suggestions where I can change any of the spring-tcp integration settings or is it solely depends on slow responsive nature from the server?
对,这确实取决于服务器。我想象一种情况,即使那 10 秒也不够,负载很大。您应该咨询您的服务器供应商以确定他们的吞吐量。