Search code examples
spring-integration

Spring Integration TcpNetServerConnectionFactory for Single Never Close TCP Connection


Does the below ensure a never close single TCP connection, as well recover from any network errors by closing and recreating the TCP connection? Our use-case is legacy and requires a single TCP connection that should keep on reading and writing. Kindly suggest.

Also, couldn't find a way to include / configure heartbeat messages in the IntegrationFlow DSL.

    @Bean
    public AbstractConnectionFactory tcpNetServerConnectionFactory() {
    
        var tcpNetServerConnectionFactory = new TcpNetServerConnectionFactory(port);
        tcpNetServerConnectionFactory.setLeaveOpen(true);
        tcpNetServerConnectionFactory.setSoTimeout(-1);
        tcpNetServerConnectionFactory.setSoKeepAlive(true);
        tcpNetServerConnectionFactory.setSoTcpNoDelay(true);
        tcpNetServerConnectionFactory.setSerializer(byteArrayLengthHeaderSerializer());
        tcpNetServerConnectionFactory.setDeserializer(byteArrayLengthHeaderSerializer());
    
        return tcpNetServerConnectionFactory;
    }

Solution

  • Yes, but the recovery is done by the client creating a new connection, not the server.