我可以在 TcpOutBoundgateway 上将 remoteTimeOut 设置为无限吗

Can i set remoteTimeOut to Infinity on TcpOutBoundgateway

我正在使用 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;
    }

Yes I want it to single thread, I want concurrent send to be blocked until the socket is available;

是;使用该配置,它将是 single-threaded;并发请求最多等待 requestTimeout 才能访问共享套接字。

https://github.com/spring-projects/spring-integration/blob/4484c4da753096094e5b376411b94ac4ba2834c6/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/TcpOutboundGateway.java#L217

try {
    haveSemaphore = acquireSemaphoreIfNeeded(requestMessage);
    connection = this.connectionFactory.getConnection();
    ...

获得套接字访问权限的请求然后最多等待 replyTimeout 答复。如果超时,则关闭套接字,以避免下一个请求得到该请求的回复。下一个请求将获得一个新的套接字。

tcpOutboundGateway.setRemoteTimeout(Long.MAX_VALUE);

这应该减少到更合理的程度,否则如果由于某种原因服务器没有回复(但保持套接字打开),您可能会永远阻塞。