【问题标题】:spring integration tcp-out-bound exceptionspring 集成 tcp-out-bound 异常
【发布时间】:2018-03-11 03:03:43
【问题描述】:

我们正在使用 Spring 集成 4.1.3。

使用 tcp-outbound-gateway 实现客户端。

在请求期间从服务器接收到一个 tcp rset 数据包并发生异常。 是什么原因? 谢谢。

    // interface
    public interface TcpSendGateway {
        public byte[] send(String text);
    } 
    // send
    byte[] response = sendGateway.send(request);




    <int:gateway id="gw"
                 service-interface="com.mainpay.service.TcpSendGateway"
                 default-request-channel="input"
                 default-reply-channel="reply"/>

    <int-tcp:tcp-connection-factory id="client"
                                    type="client"
                                    host="#{prop['app.cultureland.host']}"
                                    port="#{prop['app.cultureland.port']}"
                                    so-timeout="10000"
                                    single-use="false"
                                    so-keep-alive="true"
    />                         
    <int:channel id="input" />
    <int-tcp:tcp-outbound-gateway id="outGateway" 
                                  request-channel="input"
                                  reply-channel="reply"
                                  connection-factory="client"
                                  request-timeout="10000"                                      
                                  reply-timeout="10000"                                                                                                               
                                  />        
    <int:channel id="reply" datatype="java.lang.String" />

错误日志

▶ 17.09.29 17:07:37 [pool-2-thread-2] ERROR o.s.i.i.t.c.TcpNetConnection - Read exception 211.59.10.133:7611:51503:d2ec0199-fd15-49c0-bd99-0d864eb2145b SocketException:Connection reset
▶ 17.09.29 17:07:39 [http-nio-19900-exec-5] ERROR o.s.i.ip.tcp.TcpOutboundGateway - Tcp Gateway exception
org.springframework.messaging.MessagingException: Exception while awaiting reply; nested exception is java.net.SocketException: Connection reset
    at org.springframework.integration.ip.tcp.TcpOutboundGateway$AsyncReply.getReply(TcpOutboundGateway.java:288)

wireshark 日志 enter image description here

【问题讨论】:

    标签: java spring tcp spring-integration tcpclient


    【解决方案1】:

    我认为您应该确保您的客户端和服务器都同意(反)序列化协议。请参阅Reference Manual 了解更多信息:

    TCP 是一种流协议;这意味着必须为通过 TCP 传输的数据提供某种结构,以便接收方可以将数据划分为离散的消息。连接工厂配置为使用(反)序列化程序在消息有效负载和通过 TCP 发送的位之间进行转换。

    默认的是ByteArrayCrLfSerializer,它处理\r\n 消息分隔符。

    因此,您的客户可能会收到包裹,但由于它不符合正确的分隔符,因此无法等待回复。

    【讨论】:

      【解决方案2】:

      java.net.SocketException:连接重置

      表示服务器出于某种原因强制关闭套接字 (RST)。您需要查看服务器日志。

      也许它不期望默认的有线格式(文本以CRLF - 0x0d0a 结尾)。

      【讨论】:

      • 非常感谢。你真的帮了我很多
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-07-23
      • 2014-06-15
      • 1970-01-01
      • 1970-01-01
      • 2016-08-31
      • 2017-03-21
      • 1970-01-01
      相关资源
      最近更新 更多