gpt4 book ai didi

java - spring integration tcp-out-bound异常

转载 作者:可可西里 更新时间:2023-11-01 02:53:27 28 4
gpt4 key购买 nike

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

最佳答案

我认为您应该确保您的客户端和服务器同意(反)序列化协议(protocol)。参见 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 - spring integration tcp-out-bound异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46484905/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com