I am trying to build a generic server for always on connected clients.
The architecture consists of 4 main components
- Stateful App Servers
- Stateless Gateway Servers
- Clients Queueing
- Systems and brokers
Process flow
- Client connects to a gateway
- Gateway accepts as sends a session id back to client
- Client sends a message to gateway
- The Gateway writes the request to a Message / Task Queue
- A daemon reads the messages on the Queue and forwards them to the App Server(s)'s listening socket
- The App Servers runs the message through its business logic
- The App Server then at a later point sends a related message to the client into the gateway queue
- A thread on the gateway reads the messages in its inbound queue and then sends messages back to clients as identified in the message.
- The gateway maintains a map of Client Session Id to the Client Socket object to forward incoming messages to the Client Sockets
I am using Java Netty for gateway. App server is also in Java.
I am tempted to say that the design is like Mongrel2 but I am not completely sure. I would say this is more on the lines of the Helium edge server design of Urban Airship (http://urbanairship.com/blog/2010/08/24/c500k-in-action-at-urban-airship/)
My question is: - Is using a thread for reading messages from the inbound queue and then forwarding them to clients a good idea? Is there a better way to handle this? How do i ensure that the messages go to the respective client socket without using another thread?