Skip to main content

Install

Centrifugo provides official client SDKs for most platforms: For the full list including community SDKs, see the Centrifugo client SDK docs.

Connect

Fetch a token using your API key, then instantiate and connect the Centrifuge client. You only need one client instance — all channel subscriptions are multiplexed over the single connection. If you need more than 512 subscriptions, create additional client instances (each connection supports up to 512 channels). See Limits for details.

Subscribe to a channel

Once connected, create a subscription for the channel you want. All channel pages in this section use this same pattern — replace "channel:name" with the channel name format documented on each page.
Pass recoverable: true on channels whose namespace has history to get at-least-once delivery across reconnects. You do not need positioned: true — requesting recovery grants a stream position. See Namespace history capabilities for which channels support this, and Recovery & reliability for how to handle recovery outcomes.
Each publication event exposes a ctx object with the following structure:
ctx.data is the channel payload documented on each channel’s reference page. ctx.tags.messageId is a UUID present on every publication — use it to deduplicate messages (see Recovery & reliability → Dedup).

Snapshot + subscribe pattern

Don’t rely on the live feed alone to build initial state. Subscribe first, then seed from REST inside the subscribed handler. This closes the gap between “when you fetched the snapshot” and “when your first publication arrives”:
  1. Create the subscription with recoverable: true (which also grants a stream position — you do not need positioned: true).
  2. In the subscribed handler, fetch current state from REST.
  3. Apply live updates as publications arrive.
On reconnects, the same subscribed handler fires — check wasRecovering and recovered to decide whether you need to re-seed (see Recovery & reliability).

Cleanup

When you no longer need a subscription, clean it up to free resources:
Last modified on August 11, 2026