Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Websockets on JVM Cluster

Tags:

java

websocket

I have a relatively high level architecture question. My applications run on multiple JVMs on multiple physical nodes in a cluster. If I define a websocket endpoint so that it can be served by any of the JVMs how could I initiated a server initiated "send" message so that all appropriate connections across any JVM can send the message?

What I mean is if user A connection to JVM-A and user B connection to JVM-B and then an event on JVM-C occurs that requires user A and B to be notified how would that work? At first I was thinking of sharing the connection/session objects in distributed memory, but I dont think having that object will be enough since the physical connection is on a certain server?

Is there a more standard way to handle this problem?

like image 590
tvfoodmaps Avatar asked Oct 19 '22 04:10

tvfoodmaps


1 Answers

Suggest creating a bean that is ApplicationScoped (if JSF) or Singleton if using CDI that subscribes to a multicast socket (preferrably on a network interface that's only LAN accessible). When one websocket initiates a 'send', it also dispatches a LAN message to the multicast group (possibly including the web socket message to be redispatched). Receiving beans should check if they dispatched the sent message (depends if multicast loopback was active) and discard anything they initiated themselves, but would otherwise re-dispatch the relevant message using their own active websockets once the LAN message is received on the multicast group.

like image 121
VirtualMichael Avatar answered Oct 21 '22 22:10

VirtualMichael