【问题标题】:Spring integration TCP, force reconnectSpring集成TCP,强制重连
【发布时间】:2013-03-17 14:06:09
【问题描述】:

我有以下spring集成TCP连接:

<int-ip:tcp-connection-factory id="client" type="client" host="..." port="..." single-use="true" so-timeout="10000"/>

我希望能够在发生协议级别问题时强制重新连接。可以这样做吗?怎么样?

【问题讨论】:

    标签: spring tcp spring-integration reconnect


    【解决方案1】:

    鉴于您已将 single-use 设置为 true,因此每个请求仅使用一次套接字,因此“在失败时重新连接”毫无意义,因为无论如何都会为每个请求建立新连接。

    使用single-use="false"(共享连接),如果您使用带有&lt;int-ip:output-channel-adapter/&gt; 的工厂,您可以将client-mode 设置为true;这将在超时后自动重新连接(您可以通过在适配器上调用retryConnection() 来显式重新建立共享连接。但是,出站网关当前不支持client-mode。请参阅TCP Adapters 并使用您的浏览器查找“客户端模式”以获取更多信息。

    也就是说,使用single-use="false",您只需在客户端工厂调用getConnection(),它将重新建立共享连接(但您不能对连接做任何事情)。另外,不要对 single-use="true" 执行此操作,因为它会导致内存泄漏(除非您 close() 连接 - 这没有任何意义 - 获取连接只是为了关闭它)。

    【讨论】:

      猜你喜欢
      • 2013-04-12
      • 2016-06-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多