I need to write a Java Client application which needs to establish a TCP connection to a server which sends events(xml messages). Before receiving the events from the server, the Client will also be sending an xml message to create a channel on the server and the server will send a response back. Then the client when it receives the event messages, has to process them and respond back with the xml response message over the same TCP connection. The server is a legacy application and I have no control over it.
The server also sends health check messages to assess the channel created by the client, to which the client has to respond to, to keep the channel alive.
I am not experienced with NIO/Socket/TCP programming in Java, so wondering what would be a simple and elegant way to implement this client.
I have decent experience with Spring and am wondering if I can use Spring to wire up some components like (1) a TCP Connection Gateway/Adapter which will be responsible for the opening/monitoring the connection state (2) a Marshaller/Unmarshaller to convert the messages from XML to Java and vice versa and (3) a Message Receiver and Sender which actually receives/listens for messages and sends the responses.
One thing to remember is that, there will be tons of the event messages sent by the server and the client has to process them pretty quickly and respond immediately. So the message processing cannot happen serially.
Any suggestions or pointers to library or example code is highly appreciated.
Thanks.