【问题标题】:TCP Client Spring Integration with Legacy ServerTCP Client Spring 与 Legacy Server 的集成
【发布时间】:2020-10-11 18:47:30
【问题描述】:

我需要一些关于迁移到 Spring Integration 的帮助。 实际上,我们有一个基于 java.net 包的组件,它只包含几个带有 java 经典 TCP 客户端的类,没什么花哨的,它实际上可以通过 tcp 向旧服务器发送一些请求。这是发送和接收消息的代码:

public String sendMessage(String info) {

    try {
        PrintStream ps = new PrintStream(clientSocket.getOutputStream());
        ps.println(info);

        InputStreamReader ir = new InputStreamReader(clientSocket.getInputStream());
        BufferedReader br = new BufferedReader(ir);

        return br.readLine();

    } catch (IOException e) {
        log.debug(e.getMessage());
    }
    return "";
}

问题是我想在客户端开始使用Spring Integration,但是我无法更改服务器,因为它属于另一家公司,但是我没有收到服务器的响应,我尝试了很多配置而且一点运气都没有。 这是我现在的客户端配置:

            <int:gateway id="gw"
                 service-interface="pe.financieraoh.core.cointegrador.tcp.SimpleGateway"
                 default-request-channel="input"/>

    <int-ip:tcp-connection-factory id="client"
                                   type="client"
                                   host="localhost"
                                   port="7777"
                                   single-use="false"
                                   serializer="connectionSerializeDeserialize"
                                   deserializer="connectionSerializeDeserialize"
                                    />
    <int:channel id="input" />

    <int-ip:tcp-outbound-gateway id="outGateway"
                                 request-channel="input"
                                 reply-channel="clientBytes2StringChannel"
                                 connection-factory="client"
                                 request-timeout="10000"
                                 reply-timeout="10000" />

<bean id="connectionSerializeDeserialize" 
          class="org.springframework.integration.ip.tcp.serializer.ByteArrayLfSerializer"/>

<int:object-to-string-transformer id="clientBytes2String"
                                      input-channel="clientBytes2StringChannel" />

我尝试了很多并且总是收到 TimeOutConnection 异常,我很确定服务器没有收到我的请求,但我不能确定,因为我无权访问服务器日志。我唯一的指南是客户端中的旧代码可以正常工作。 感谢您的帮助。

这是来自服务器的日志,我尝试了几种反序列化器,结果相同,2020-06-21 23:47:10.377 ERROR 1 --- [nio-8080-exec-7] osiip .tcp.TcpOutboundGateway:Tcp 网关异常 org.springframework.integration.MessageTimeoutException:在 org.springframework.integration.ip.tcp.TcpOutboundGateway.getReply 等待响应超时(TcpOutboundGateway.java:243)~[spring-integration-ip- 5.3.0.RELEASE.jar:5.3.0.RELEASE]

【问题讨论】:

  • 请用日志更新问题,而不是在 cmets 中发布。

标签: spring tcp spring-integration tcpclient


【解决方案1】:

对于println 和readLine 的等效项,您需要ByteArrayLfSerializer(如果在Linux/Unix/Mac 上运行客户端)或默认ByteArrayCrLfSerializer(如果在Windows 上运行客户端)。

如果这不起作用,请使用 WireShark 或类似工具查看网络流量。

【讨论】:

  • 感谢 Gary 的回答,我对序列化程序没有运气,我将尝试查看 wireshark 发生了什么,但我需要检查如何做到这一点,因为连接是在两台服务器之间,我无法从我的本地计算机访问 tcp 服务器。
  • 你不需要;您可以在客户端计算机上运行 wireshark 来捕获网络流量。另一种可能性是服务器正在关闭套接字以发出结束信号(而不是 CRLF 或 LF)。在这种情况下,请尝试ByteArrayRawDeserializer。
  • 太好了,是的,我将在 openshift 中使用边卡 tcpdump 来捕获流量,我想明天我会得到更多信息,同时我会尝试 ByteArrayRawDeserializer,再次感谢 Gary
  • 您好,我可以再次使用 tcpdump 和 wireshark 检查配置是否正常,我还有另一个问题,就像防火墙或网关系统一样,它正在过滤与外部服务器的通信,但是我不知道,为什么会这样。消息在网关中接收良好,但在最终系统中没有接收,因此我收到“超时异常”,我将使用 Operation 或 DevOps 检查。再次感谢加里的帮助
猜你喜欢
  • 1970-01-01
  • 2017-03-21
  • 2017-03-16
  • 2022-08-17
  • 1970-01-01
  • 2020-10-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多