I am writing a chat-like application using WebSockets using a Jetty 9.3.7 WebSockets server running on AWS/EC2. A description of the architecture is below:
(a) The servers are based on HTTPS
(wss
). I am thinking of using HAProxy
using IP hash-based LB for this. The system architecture will look like this:
-->wss1: WebSocket server 1
/
clients->{HAProxy LB} -->wss2: WebSocket server 2
(a, b,..z) \
-->wss3: WebSocket server 3
I am terminating HTTPS
/wss
on the LB per these instructions.
(b) Clients a...z
connect to the system and will connect variously to wss1
, wss2
or wss3
etc.
(c) Now, my WebSocket application works as follows. When one of the clients pushes a message, it is sent to the WS server the client is connected to (say wss1
, and then that message is disseminated to a few of the other clients (the set of clients being programmatically determined at my WebSocket application running on wss1
). E.g., a
creates a message Hey guys!
and pushes it to wss1
, which is then pushed to clients b
and c
so that b
and c
receive Hey guys!
message. b
has a WebSocket connection to server wss2
and c
has a WebSocket connection to wss3
.
My question is, to push the message from the message receiving server, like (c) above, wss1
needs to know the WebSocket session/connection to b
and c
which may well be on a different WebSocket server. Can I use session clustering on Jetty to retrieve the sessions b
and c
are connected to? If not, what's the best way to provide this lookup while load balancing Jetty WebSockets?
Second, if I do use session clustering or some such method to retrieve the session, how can I use the sessions for b
and c
on wss1
to send the message to b
and c
? It appears like there is no way to do this except with some sort of communication between the servers. Is this correct?
If I have to use session clustering for this, is there a github example you can point me to?
Thanks!