Reputation: 1120
How can I configure Spring to receive a TCP connection and then send data over it? I have data stored in a RabbitMQ queue, and I need to send this data over an incoming connection.
I assume client is working as client-mode=true
according to the documentation. I have found an example on how to behave as a client in this use-case, but I can't find an example for the server side. Could anyone point me in the right direction?
I am not sure if this is a standard use-case, it seems backwards to me that the client is starting the connection and not the server, but I have little experience with TCP.
Upvotes: 0
Views: 435
Reputation: 174494
You don't need client mode; that's for when you want an inbound adapter to initiate the socket open. Use a TcpSendingMessageHandler
with a server connection factory, to listen on the port.
Add an ApplicationListener
bean that listens for a TcpConnectionOpenEvent
see TCP Connection Events.
The event will have the connection id, which you must capture and set in a message header (IpHeaders.CONNECTION_ID
) for any messages sent, so the adapter knows where to send the message.
Upvotes: 1