【问题标题】:Spring Integration : TCP disable respnse readSpring集成:TCP禁用响应读取
【发布时间】:2016-04-04 06:40:27
【问题描述】:

我有以下要求

  1. 连接到套接字 (TCP)
  2. 发送初始化消息[服务器将无响应]
  3. 检查连接是否有效,如果是,发送轮询消息。
  4. 如果有响应处理呢。

我正在尝试为 TCP 连接使用 Spring 集成,但是当我尝试执行第二步时,框架会等待响应。有没有办法将其配置为不等待步骤 2 中的响应?

以下是 Spring 配置:

<int:gateway default-request-channel="msOutbound"
    service-interface="com.home.tcp.UserService" id="gw" />

<int-ip:tcp-outbound-gateway id="tcpObGw"
    connection-factory="client" request-channel="msOutbound"
     />

<int-ip:tcp-connection-factory id="client"
    type="client" deserializer="serDeSer" serializer="serDeSer"
    host="remoteServer" port="valid port"  single-use="true" />

<bean id="serDeSer"
    class="org.springframework.integration.ip.tcp.serializer.ByteArrayStxEtxSerializer" />

Java 代码:

service.send("init msg"); // The program exits with no response exception.
service.send("polling message"); //Never executed.

【问题讨论】:

    标签: java spring tcp spring-integration


    【解决方案1】:

    网关是一种请求/响应机制(一个请求,一个响应)。您将single-use 设置为true,因此即使第一个返回响应,第二个也会继续使用另一个套接字。

    对于您的场景,您需要将 single-use 设置为 false 并在第一个 send 周围放置一个 try/catch,因为您预计那里会出现异常。

    为了改善计时,您应该将网关上的remoteTimeout 设置为非常小的值 (0) 以仅用于第一次发送,然后合理地增加它。

    【讨论】:

      猜你喜欢
      • 2017-03-21
      • 2018-12-12
      • 1970-01-01
      • 1970-01-01
      • 2021-07-09
      • 2012-03-07
      • 2018-11-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多