'Can i set remoteTimeOut to Infinity on 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;
}
Solution 1:[1]
Yes I want it to single thread, I want concurrent send to be blocked until the socket is available;
Yes; with that configuration, it will be single-threaded; concurrent requests will wait for up to requestTimeout to get access to the shared socket.
try {
haveSemaphore = acquireSemaphoreIfNeeded(requestMessage);
connection = this.connectionFactory.getConnection();
...
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.
tcpOutboundGateway.setRemoteTimeout(Long.MAX_VALUE);
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).
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Gary Russell |
