Spring integration 将keep alive配置为使连接始终处于活动状态

Spring integration 将keep alive配置为使连接始终处于活动状态,spring-integration,Spring Integration,我有一个tcp客户机-服务器应用程序,在该应用程序中,客户机打开一个一次性连接,并在配置时间后断开连接。如何配置它保持连接始终处于活动状态,在关闭连接时重新连接,并确保多个客户端连接对服务器开放 客户端配置: <int-ip:tcp-connection-factory id="client" type="client" host="${server.TCP.host}" port="${server.TCP.port}" single-use="true"

我有一个tcp客户机-服务器应用程序,在该应用程序中,客户机打开一个一次性连接,并在配置时间后断开连接。如何配置它保持连接始终处于活动状态,在关闭连接时重新连接,并确保多个客户端连接对服务器开放

客户端配置:

<int-ip:tcp-connection-factory id="client"
    type="client"
    host="${server.TCP.host}"
    port="${server.TCP.port}"
    single-use="true"
    so-timeout="${client.TCP.socketTimeOut}" />

<int-ip:tcp-outbound-gateway id="outGateway"
    request-channel="bytesOut"
    reply-channel="bytesIn"
    connection-factory="client"
    request-timeout="${client.TCP.requestTimeOut}"
    reply-timeout="${client.TCP.replyTimeout}" />
<int-ip:tcp-connection-factory id="tcpServerConnFactory"
    type="server" 
    port="${service.tcp.port}" 
    using-nio="true"
    single-use="false" 
    so-timeout="${service.tcp.socketTimeout}"
    task-executor="taskExecutor"/>

<int-ip:tcp-inbound-gateway 
    id="tcpInboundGateway" 
    connection-factory="tcpServerConnFactory" 
    request-channel="bytesInChannel"
    reply-channel="bytesOutChannel"
    error-channel="errorChannel" />

服务器配置:

<int-ip:tcp-connection-factory id="client"
    type="client"
    host="${server.TCP.host}"
    port="${server.TCP.port}"
    single-use="true"
    so-timeout="${client.TCP.socketTimeOut}" />

<int-ip:tcp-outbound-gateway id="outGateway"
    request-channel="bytesOut"
    reply-channel="bytesIn"
    connection-factory="client"
    request-timeout="${client.TCP.requestTimeOut}"
    reply-timeout="${client.TCP.replyTimeout}" />
<int-ip:tcp-connection-factory id="tcpServerConnFactory"
    type="server" 
    port="${service.tcp.port}" 
    using-nio="true"
    single-use="false" 
    so-timeout="${service.tcp.socketTimeout}"
    task-executor="taskExecutor"/>

<int-ip:tcp-inbound-gateway 
    id="tcpInboundGateway" 
    connection-factory="tcpServerConnFactory" 
    request-channel="bytesInChannel"
    reply-channel="bytesOutChannel"
    error-channel="errorChannel" />

客户端的一次性使用意味着-每个套接字用于一个请求/回复,然后关闭

single use=“false”
时,所有请求/回复都使用一个共享连接,并且每个调用方都阻止等待套接字

您可以使用“CachingClientConnectionFactory”来维护永久连接池-请参阅

如上所述,TCP套接字可以一次性使用(一个请求/响应)或共享。在高容量环境中,共享套接字不能与出站网关配合使用,因为套接字一次只能处理一个请求/响应

为了提高性能,用户可以使用协作通道适配器而不是网关,但这需要应用程序级别的消息关联。有关更多信息,请参阅第31.8节“TCP消息相关性”

SpringIntegration2.2引入了缓存客户端连接工厂,其中使用了共享套接字池,允许网关使用共享连接池处理多个并发请求


即将发布的5.0版本-目前处于里程碑7(5.0.0.M7)。每个调用线程都有一个保持连接打开的连接。

删除客户端和服务器上的超时,并在客户端设置single use=false,就达到了我想要的效果。但是,如果服务器重新启动,我如何保证客户端将自动连接?如果当前连接关闭,则在发送下一条消息时会自动创建新连接。感谢@Gary提供的宝贵建议。