首页 文章

忽略Spring集成TCP服务器的ServiceActivator中的响应

提问于
浏览
0

我知道spring集成有TcpInboundGateway,TcpOutboundGateway和ByteArrayStxEtxSerializer来处理通过TCP端口传输的数据 .

如果TCP服务器需要读取从客户端发送的所有数据然后处理它,ByteArrayStxEtxSerializer工作得很好 . (请求和响应模型)我使用single-use = false,以便可以在同一连接中处理多个请求 .

例如,如果客户端发送0x02AAPL0x03,则服务器可以发送AAPL价格 .

如果客户端发送0x02AAPL0x030x02GOOG0x03,我的TCP服务器正在工作 . 它发送AAPL和GOOG价格的价格 .

如果有无效的自动收报机,TCP服务器应该忽略它并给出有效代码的价格 .

当客户端发送0x02AAPL0x030x2INVALIDTICKER0x030x02GOOG0x03时,我的客户端收到AAPL价格并等待永远和超时 .

我的TCP服务器使用ServiceActivator并为INVALIDTICKER返回null .

我想知道为什么客户没有收到有效价格 . 套接字outputStream被阻塞了吗?是否有任何设置允许跳过ServiceActivator的一些响应?

请帮忙 .

我们正在使用spring集成4.2.6.RELEASE版本和java 8 .

这是我的 spring 配置:

<bean id="connectionSerializeDeserialize" class="org.springframework.integration.ip.tcp.serializer.ByteArrayStxEtxSerializer"/>

    <int-ip:tcp-inbound-gateway id="gatewayCrLf"
        connection-factory="crLfServer"
        request-channel="serverBytes2StringChannel"
        error-channel="errorChannel"
        reply-timeout="10000"/> <!-- reply-timeout works on inbound-gateway -->

    <int:channel id="toSA" />

    <int:service-activator input-channel="toSA"
        ref="myService"
        method="prepare"/>

    <int:object-to-string-transformer id="serverBytes2String"
        input-channel="serverBytes2StringChannel"
        output-channel="toSA"/>

    <int:transformer id="errorHandler"
        input-channel="errorChannel"
        expression="payload.failedMessage.payload + ':' + payload.cause.message"/>

谢谢

1 回答

  • 1
    <int-ip:tcp-inbound-gateway id="gatewayCrLf"
        connection-factory="crLfServer"
        request-channel="serverBytes2StringChannel"
        error-channel="errorChannel"
        reply-timeout="10000"/> <!-- reply-timeout works on inbound-gateway -->
    

    返回 null 结束流程,但网关不知道 - 可能是回复可能来自不同的线程 - 他无法告诉他永远不会得到这个请求的回复 .

    由于您已将回复超时设置为10秒,因此网关(套接字)线程将等待该时间,然后才能再执行任何工作 .

    鉴于您的流程很简单,您可以安全地将回复超时设置为 0 ,因为当有 is 回复时,它已经可以处理了 .

相关问题