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

发布于 2025-01-14 11:34:50 字数 1196 浏览 2 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一花一树开 2025-01-21 11:34:50

是的,我希望它是单线程的,我希望并发发送被阻止,直到套接字可用;

是的;使用该配置,它将是单线程的;并发请求将等待 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);

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

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.

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();
    ...

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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文