【发布时间】:2017-03-16 02:21:11
【问题描述】:
我知道 spring 集成有 TcpInboundGateway、TcpOutboundGateway 和 ByteArrayLengthHeaderSerializer 来处理来自 TCP 端口的数据。
ByteArrayLengthHeaderSerializer 如果 TCP 服务器需要读取从客户端发送的所有数据然后处理它,则效果很好。 (请求和响应模型)
例如,如果客户端发送 9AAPL,那么服务器可以发送 AAPL 价格。
我正在寻找一种客户端可以与服务器交互而无需在多个请求中关闭连接的方式。
例如:如果客户端发送 9AAPL,那么服务器应该发送 AAPL 价格并等待来自客户端的另一个请求而不关闭连接。这种交互可以一直持续到客户端在 50 秒内发送 5 个或没有来自客户端的响应。
您能否建议需要用于此交互行为的 Spring 集成类(TCP 网关、序列化器等)?
我们正在使用 spring integration 4.2.6.RELEASE 版本和 java 8。这些版本足够好还是我们需要升级到新版本?
更新: 这是我的弹簧配置:
<bean id="connectionSerializeDeserialize" class="org.springframework.integration.ip.tcp.serializer.ByteArrayLengthHeaderSerializer"/>
<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"/>
谢谢
【问题讨论】:
标签: java sockets tcp spring-integration