I'm trying to implement the following scenario using Spring Integration:
This is my config:
<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"/>
I can receive messages sent from the server, but I have no idea how to convert a string. javaDeserializer is not invoked when messages arrive.
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
With this example, you can send messages and process the reply from the server, but the connection will close and not kept listening to the messages from the server. Any idea how to solve this?
Thanks in advance.
Eduardo
TCP is a streaming protocol and has no concept of "messages". The framework uses a serializers (for output) and deserializers (for input) to encode/decode messages to/from the stream.
The framework has a number of standard deserializers (e.g. messages are delimited by \n or \r\n etc).
If your data doesn't fit into one of these standard formats, you need to provide a custom deserializer. A good place to start would be to look at the standard deserializers and subclass the AbstractByteArraySerializer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With