我可以在 TcpOutBoundgateway 上将 RemoteTimeOut 设置为无限吗
我正在使用 CachingClientConnectionFactory,如何保持连接处于活动状态,在默认的 RemoteTimeOut 经过后关闭连接,我可以将 RemoteTimeOut 设置为 LONG.MAX_VALUE 吗?
谢谢
@Bean
public AbstractClientConnectionFactory clientConnectionFactory() {
TcpNioClientConnectionFactory tcpNioClientConnectionFactory = new TcpNioClientConnectionFactory(host, port);
tcpNioClientConnectionFactory.setUsingDirectBuffers(true);
tcpNioClientConnectionFactory.setApplicationEventPublisher(applicationEventPublisher);
return new CachingClientConnectionFactory(tcpNioClientConnectionFactory, connectionPoolSize);
}
@Bean
public MessageChannel outboundChannel() {
return new DirectChannel();
}
@Bean
@ServiceActivator(inputChannel = "outboundChannel")
public MessageHandler outboundGateway(AbstractClientConnectionFactory clientConnectionFactory) {
TcpOutboundGateway tcpOutboundGateway = new TcpOutboundGateway();
tcpOutboundGateway.setConnectionFactory(clientConnectionFactory);
tcpOutboundGateway.setRemoteTimeout(Long.MAX_VALUE);
tcpOutboundGateway.setRequestTimeout(5_000);
return tcpOutboundGateway;
}
I am using CachingClientConnectionFactory, How can i keep the connections alive, its closing out after default remoteTimeOut elapses, Can I set the remoteTimeOut to LONG.MAX_VALUE?
Thanks
@Bean
public AbstractClientConnectionFactory clientConnectionFactory() {
TcpNioClientConnectionFactory tcpNioClientConnectionFactory = new TcpNioClientConnectionFactory(host, port);
tcpNioClientConnectionFactory.setUsingDirectBuffers(true);
tcpNioClientConnectionFactory.setApplicationEventPublisher(applicationEventPublisher);
return new CachingClientConnectionFactory(tcpNioClientConnectionFactory, connectionPoolSize);
}
@Bean
public MessageChannel outboundChannel() {
return new DirectChannel();
}
@Bean
@ServiceActivator(inputChannel = "outboundChannel")
public MessageHandler outboundGateway(AbstractClientConnectionFactory clientConnectionFactory) {
TcpOutboundGateway tcpOutboundGateway = new TcpOutboundGateway();
tcpOutboundGateway.setConnectionFactory(clientConnectionFactory);
tcpOutboundGateway.setRemoteTimeout(Long.MAX_VALUE);
tcpOutboundGateway.setRequestTimeout(5_000);
return tcpOutboundGateway;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的;使用该配置,它将是单线程的;并发请求将等待
requestTimeout
才能访问共享套接字。https://github.com/spring-projects/spring-integration/blob/4484c4da753096094e5b376411b94ac4ba2834c6/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/TcpOutboundGateway.java#L217
获取套接字访问权限的请求然后等待回复时间最长为
replyTimeout
。如果超时,套接字将被关闭,以避免下一个请求得到该请求的回复。下一个请求将获得一个新的套接字。这应该减少到更合理的程度,否则如果由于某种原因服务器不回复(但保持套接字打开),您可能会永远阻塞。
Yes; with that configuration, it will be single-threaded; concurrent requests will wait for up to
requestTimeout
to get access to the shared socket.https://github.com/spring-projects/spring-integration/blob/4484c4da753096094e5b376411b94ac4ba2834c6/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/TcpOutboundGateway.java#L217
The request that gets access to the socket then waits for up to
replyTimeout
for a reply. If it times out, the socket is closed, to avoid the next request getting this request's reply. The next request will get a new socket.That should be reduced to something more reasonable otherwise you could block forever if, for some reason, the server doesn't reply (but keeps the socket open).