最大消息长度之前找不到CRLF:具有有效负载 - 划分转换器的2048



我在我的TCP客户端中使用有效载荷 - 驱动器 - 转换器,如下所示。

    <context:property-placeholder />
<int:gateway id="gw"
    service-interface="myGateway"
    default-request-channel="objectIn"
    default-reply-channel="objectOut" />
<int-ip:tcp-connection-factory id="client"
    type="client"
    host="${client.server.TCP.host}"
    port="${client.server.TCP.port}"
    single-use="true"
    so-timeout="10000" />
<int:channel id="objectIn" />
<int:payload-serializing-transformer input-channel="objectIn" output-channel="bytesOut"/>
<int:channel id="bytesOut" />   
<int-ip:tcp-outbound-gateway id="outGateway"
    request-channel="bytesOut"
    reply-channel="bytesIn"
    connection-factory="client"
    request-timeout="10000"
    reply-timeout="10000" />
<int:channel id="bytesIn" />
<int:payload-deserializing-transformer input-channel="bytesIn" output-channel="objectOut" />
<int:channel id="objectOut" />

上述可用于消息长度&lt;2048但是,如果消息超过此限制,我会收到以下错误。

Caused by: java.io.IOException: CRLF not found before max message length: 2048
at org.springframework.integration.ip.tcp.serializer.ByteArrayCrLfSerializer.fillToCrLf(ByteArrayCrLfSerializer.java:66)
at org.springframework.integration.ip.tcp.serializer.ByteArrayCrLfSerializer.deserialize(ByteArrayCrLfSerializer.java:44)
at org.springframework.integration.ip.tcp.serializer.ByteArrayCrLfSerializer.deserialize(ByteArrayCrLfSerializer.java:31)
at org.springframework.integration.ip.tcp.connection.TcpNetConnection.getPayload(TcpNetConnection.java:120)
at org.springframework.integration.ip.tcp.connection.TcpMessageMapper.toMessage(TcpMessageMapper.java:113)
at org.springframework.integration.ip.tcp.connection.TcpNetConnection.run(TcpNetConnection.java:165)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)

在这种情况下,如何在有效负载 - 划分转换器上设置MaxMessagesize属性?

这与变压器无关;错误在出站网关中。

首先,您不应使用基于文本的划界用于入站TCP消息;一个序列化对象包含二进制数据,可能包含中间某个地方的CRLF(0x0d0a)。

您应该使用网关中的二进制能力的避难所之一。

您可以在参考手册中阅读有关TCP序列化器/避难所的信息。

您应该配置出站网关,以在serializerdeserializer属性中使用ByteArrayLengthHeaderSerializer;它可以处理二进制有效载荷。

还需要更改远程系统以使用长度标头,而不是使用CRLF检测消息的末尾。如果远程系统也是弹簧集成,则只需更改其序列化器/求职者。

对于使用基于文本的消息传递的其他读者,可以使用ByteArrayCrlfSerializer配置maxMessageSize,默认为2048。

ByteArrayLengthHeaderSerializer还具有可配置的maxMessageSize(也有2048) - 这是在收到不良消息的情况下预防OOM条件。

相关内容

最新更新