Reputation: 9
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.
Upvotes: 0
Views: 425
Reputation: 533442
I would be extremely surprised if you cannot handle the messages serially (unless you client performs particularly badly)
I would use a simple IO socket and a STaX event parser to decode the messages. The Javolution XML parser is pretty quick. I don't like Spring because it tends to make complex solutions of simple problem IMHO. You should be able to do all this with just one class file and a few small nested classes. Don't be afraid to write the code yourself, this is how you become a more experienced developer.
I would expect you should be able to handle 1000+ large XML messages per second and as much as 200,000 small XML messages per second with one reader thread.
Upvotes: 1