spring 集成 tcp 出站异常

spring integration tcp-out-bound exception

我们正在使用 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

我认为您应该确保您的客户端和服务器同意(反)序列化协议。有关详细信息,请参阅 Reference Manual

TCP is a streaming protocol; this means that some structure has to be provided to data transported over TCP, so the receiver can demarcate the data into discrete messages. Connection factories are configured to use (de)serializers to convert between the message payload and the bits that are sent over TCP.

默认的 ByteArrayCrLfSerializer 处理 \r\n 消息定界符。

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

java.net.SocketException: Connection reset

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

也许它不需要默认的连线格式(文本以 CRLF - 0x0d0a 终止)。