0

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!

Sonny
  • 2,103
  • 1
  • 26
  • 34
  • The TL;DR version of my question would be: In http://stackoverflow.com/questions/15646213/how-do-i-access-instantiated-websockets-in-jetty-9?rq=1, the Joakim's response describes how to retrieve WebSocket session stored locally on the same server. How do I achieve this when the sessions are on different servers? If session clustering is the way, is there a place where I can find Jetty's session clustering schema? – Sonny Apr 17 '16 at 21:41
  • I found the clustering schema here: https://www.eclipse.org/jetty/documentation/9.2.3.v20140905/session-clustering-jdbc.html – Sonny Apr 17 '16 at 21:54

1 Answers1

0

I think session clustering is not a right tool. Message Oriented Middleware (MOM) supporting publish and subscribe model should be enough to cluster multiple real-time applications. As an author of Cettia, a real-time application framework, I've used publish and subscribe model to scale application horizontally.

The basic idea is

  1. A message to be exchanged through MOM is an operation applying to each server locally. For example, operation can be 'sending a message to all clients'. Here all clients means ones that connect to server to execute a given operation.
  2. Every server subscribe the same topic of MOM. When some message is given by the topic, server deserializes it into operation and executes the operation locally. It happens on every server.
  3. If some operation happens on some server, that server should serialize it into message and publish it to the topic.

With Cettia, all you need is to plug your MOM into cettia application. If you want to make it from scratch, you need to implement the above ideas.

Here's working examples per some MOMs. Though they are examples written in Cettia, it might help you understand how the above idea works.

Donghwan Kim
  • 1,111
  • 7
  • 18