By and large, there are two kinds of states in a WebSocket application

User/client specific : related to a connected user/ Session e.g. user ID, list of subscriptions, last message received etc.

: related to a connected user/ e.g. user ID, list of subscriptions, last message received etc. Global: state which is relevant across your application and something which all connected users/ Session s might be able to use

User specific state

This can be handled using getUserProperties method on the Session object – this exposes a Map which you can use to store anything ( Object type) using a String type key

Global state

There are multiple options here as well. Please note that these are scoped to a specific Endpoint

getUserProperties in EndpointConfig – it exposes the same Map interface as the one in Session . Since the WebSocket runtime creates a single instance of an EndpointConfig object per Endpoint , it can be used a global state store

Another option is to encapsulate some of the common/global logic in a custom Configurator implementation which can be accessed & used within the endpoint logic

Further reading

Cheers!