Install
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.
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 thesubscribed handler. This closes the gap between “when you fetched the snapshot” and “when your
first publication arrives”:
- Create the subscription with
recoverable: true(which also grants a stream position — you do not needpositioned: true). - In the
subscribedhandler, fetch current state from REST. - Apply live updates as publications arrive.
subscribed handler fires — check wasRecovering and recovered to decide
whether you need to re-seed (see
Recovery & reliability).