Spring TCP 集成仅每 30 秒以上读取一次
Spring TCP Integration only reads every 30+ seconds
我在使用 Spring-Integration 制作 TCP 服务器时遇到问题。
我已将我的服务器设置为接受来自黑盒客户端的 TCP 连接。客户端将连接到服务器并开始定期向其发送字符串数据。
我看到的是连接建立后(我从客户端得到确认)直到大约 30 秒后我才在服务器上收到打印语句,我总共收到 5 条消息一次。
我已经通过 wireshark 监控传入数据并且客户端定期发送数据,但服务器没有足够频繁地从 incomingStream 读取数据。有没有办法配置 TcpServer 使其更频繁地从传入客户端读取数据?
fun flow() = IntegrationFlows.from(
Tcp.inboundAdapter(Tcp.nioServer(port).serializer(ByteArrayRawSerializer()).deserializer(ByteArrayRawSerializer()))
.errorChannel(errorChannel())
)
.transform(ObjectToStringTransformer())
.handle { payload: String, headers: MessageHeaders ->
println(payload)
}
.get()
ByteArrayRawSerializer
使用套接字关闭来检测消息的结束。
TCP 是一种流协议,如果您想通过套接字发送多条消息,则需要以某种方式分隔数据,以便服务器可以确定一条消息何时结束以及下一条消息何时开始。参见 the documentation。
TCP is a streaming protocol. This means that some structure has to be provided to data transported over TCP so that the receiver can demarcate the data into discrete messages. Connection factories are configured to use serializers and deserializers to convert between the message payload and the bits that are sent over TCP. This is accomplished by providing a deserializer and a serializer for inbound and outbound messages, respectively. Spring Integration provides a number of standard serializers and deserializers.
...
The ByteArrayRawSerializer
, converts a byte array to a stream of bytes and adds no additional message demarcation data. With this serializer (and deserializer), the end of a message is indicated by the client closing the socket in an orderly fashion. When using this serializer, message reception hangs until the client closes the socket or a timeout occurs.
我的猜测是客户端在发送消息后没有关闭连接并且有 30 秒的 SO 超时(在客户端或服务器上 - 你没有显示你的连接工厂配置)。
我在使用 Spring-Integration 制作 TCP 服务器时遇到问题。 我已将我的服务器设置为接受来自黑盒客户端的 TCP 连接。客户端将连接到服务器并开始定期向其发送字符串数据。
我看到的是连接建立后(我从客户端得到确认)直到大约 30 秒后我才在服务器上收到打印语句,我总共收到 5 条消息一次。
我已经通过 wireshark 监控传入数据并且客户端定期发送数据,但服务器没有足够频繁地从 incomingStream 读取数据。有没有办法配置 TcpServer 使其更频繁地从传入客户端读取数据?
fun flow() = IntegrationFlows.from(
Tcp.inboundAdapter(Tcp.nioServer(port).serializer(ByteArrayRawSerializer()).deserializer(ByteArrayRawSerializer()))
.errorChannel(errorChannel())
)
.transform(ObjectToStringTransformer())
.handle { payload: String, headers: MessageHeaders ->
println(payload)
}
.get()
ByteArrayRawSerializer
使用套接字关闭来检测消息的结束。
TCP 是一种流协议,如果您想通过套接字发送多条消息,则需要以某种方式分隔数据,以便服务器可以确定一条消息何时结束以及下一条消息何时开始。参见 the documentation。
TCP is a streaming protocol. This means that some structure has to be provided to data transported over TCP so that the receiver can demarcate the data into discrete messages. Connection factories are configured to use serializers and deserializers to convert between the message payload and the bits that are sent over TCP. This is accomplished by providing a deserializer and a serializer for inbound and outbound messages, respectively. Spring Integration provides a number of standard serializers and deserializers.
...
The
ByteArrayRawSerializer
, converts a byte array to a stream of bytes and adds no additional message demarcation data. With this serializer (and deserializer), the end of a message is indicated by the client closing the socket in an orderly fashion. When using this serializer, message reception hangs until the client closes the socket or a timeout occurs.
我的猜测是客户端在发送消息后没有关闭连接并且有 30 秒的 SO 超时(在客户端或服务器上 - 你没有显示你的连接工厂配置)。