Skip to content

Subscriptions

Subscriptions allow a WebSocket client to receive messages published to a channel.

Built-in Subscribe/Unsubscribe

The framework includes built-in handlers for subscribe and unsubscribe opcodes. The client sends:

OpcodePayloadDescription
Opcode_ClientSubscribe{channel: "channel-name"}Subscribe to a channel
Opcode_ClientUnsubscribe{channel: "channel-name"}Unsubscribe from a channel

The handlers::subscribe handler processes the request, validates authorization for private/presence channels, and registers the subscription.

Subscriptions Registry

Subscriptions are managed by clients::registry and tracked in websocket::subscriptions using a Boost.MultiIndex container for efficient lookups by session, channel, and node.

Subscription Limits

Configure limits per session and across the node:

cpp
config.websocket_.max_subscriptions_per_session_.store(1000);
config.websocket_.max_total_channels_.store(10000);

Subscription Lifecycle

  • Subscriptions are per-session — each WebSocket connection manages its own set
  • When a client disconnects, all their subscriptions are cleaned up automatically
  • Subscriptions persist only for the duration of the WebSocket connection