Search code examples
javawebsocketcluster-computinghazelcastpayara

Clustering Websockets Tyrus Java


I implemented a cluster on Payara Server with 3 Nodes (A, B & C) as Standalone Instances. I use HAproxy as load balancer and everything works fine.

I added WebSockets in my project and HAProxy switches automatically from HTTP to tunnel mode when the client request a websocket.

My problem is this : I need to retrieve websocket session regardless of connected node. For example: "I have 3 users connected to application. User 1 and User 2 are connected to the Node A. User 3 is connected to the Node B. An event occurs on the Node C that requires user 1 and 3 to be notified. But I haven't on the Node C User 1 and User 2 sessions."

I tried to use a Hazelcast distributed List to store sessions at the User connection (OnOpen method). But when I called "add" method on the list, this throws a HazelcastSerializationException because Tyrus Session Object isn't Serializable.

How can I resolve my problem?

Thanks


Solution

  • I doubt that transferring WebSocket sessions would help you, as you need to notify the users from the node they are connected to.

    You probably want to notify nodes A and B from the node C in order to update the users connected to them. To do that, you could use Hazelcast Topic to send a message to all nodes in the cluster and retrieve the message by the node that has the WebSocket session (edited). You need to get the information from node C to the other nodes that have the session, not the other way around. Passing session to another node would be of no use, as the session is applicable only to an open WebSocket connection.

    (edited) Before I suggested to use Hazelcast executor service instead of the Topic, but that causes classloader issues.