我正在尝试使用Spring Integration实现以下场景:
- 我需要通过TCP IP连接到服务器并处理接收到的消息。
- 我需要向相同的服务器发送消息,从中接收并处理响应。
这是我的配置:
<channel id="input">
<interceptors>
<wire-tap channel="logger"/>
</interceptors>
</channel>
<logging-channel-adapter id="logger" level="DEBUG" log-full-message="true"/>
<ip:tcp-connection-factory id="factory" type="client" host="localhost" port="9004" single-use="false"
using-nio="true" deserializer="javaDeserializer"/>
<ip:tcp-inbound-channel-adapter id="inbound" channel="input" connection-factory="factory" client-mode="true"
retry-interval="5000"/>
我可以接收来自服务器发送的消息,但我不知道如何将字符串转换。当消息到达时,javaDeserializer没有被调用。
2014-01-19 05:47:20 DEBUG TcpNioConnection:380 - localhost:9004:74154fb2-f77c-4036-9142-e756e53a6ac6 Reading...
2014-01-19 05:47:20 DEBUG TcpNioConnection:324 - Read 26 into raw buffer
2014-01-19 05:47:25 DEBUG TcpNioConnection:380 - localhost:9004:74154fb2-f77c-4036-9142-e756e53a6ac6 Reading...
2014-01-19 05:47:25 DEBUG TcpNioConnection:324 - Read 26 into raw buffer
2014-01-19 05:47:30 DEBUG TcpNioConnection:380 - localhost:9004:74154fb2-f77c-4036-9142-e756e53a6ac6 Reading...
2014-01-19 05:47:30 DEBUG TcpNioConnection:324 - Read 26 into raw buffer
2014-01-19 05:47:35 DEBUG TcpNioConnection:380 - localhost:9004:74154fb2-f77c-4036-9142-e756e53a6ac6 Reading...
2014-01-19 05:47:35 DEBUG TcpNioConnection:324 - Read 26 into raw buffer
通过 this 的例子,你可以发送消息并处理服务器的回复,但连接会关闭而不是保持监听来自服务器的消息。有什么解决办法吗?
提前感谢。
Eduardo
jstack
或VisualVM
获取线程转储以查看线程正在做什么。 - Gary Russell