This page has longer, end-to-end examples. Each combines several Data methods into a realistic mini-app. Each is self-contained. They assume that the SDK is installed and that a relay token is available in CLUTCHCALL_CREDENTIALS.

IoT device + dashboard

A device publishes retained boot state, lossy telemetry, and reliable alerts. A dashboard bootstraps from retained values and then tracks live data.

Microservice event bus

Typed pub/sub across services. Producers publish once. Many consumers each subscribe to their own slice of the topic tree.

Recipe 1 — IoT device + dashboard

Each device in a fleet reports:
  • Retained state at boot (devices/<id>/state). A dashboard that joins late thus sees which devices are online without a wait for a heartbeat.
  • Lossy telemetry (sensors/<id>/temperature) on the datagram lane.
  • Reliable alerts (events/alerts/<id>) on the ordered lane.
1

The device publisher

Announce retained state. Loop telemetry on the lossy lane. Send alerts on the reliable lane. On shutdown, clear the retained state. The dashboard then reads “offline.”
2

The dashboard

The dashboard uses one client and three subscriptions. The retained devices/+/state values arrive on attach (msg.retained === true). The dashboard thus bootstraps the fleet roster immediately. Then it tracks live telemetry and alerts.
The dashboard never needed a per-device subscription. fromClientId plus the topic do the demux. The retained state topics make the roster instantly correct on connect and reconnect. The SDK replays subscriptions after a transient drop. The relay re-emits retained values.

Recipe 2 — Typed event bus

Producers publish domain events once to events/<svc>/<kind>. Many consumers each subscribe to their own subtree and dispatch by topic. There is no broker to run. The relay mesh fans out.
1

The producer

Send events on the reliable lane. Then no event is dropped.
2

The consumer

The consumer uses one subscription on events/#, a dispatch table of handlers keyed by sub-filter, and a fallback for unmatched topics. The SDK filters client-side. A new handler thus costs nothing on the wire.
3

Scale out consumers

Run as many consumer instances as you want. Each instance opens its own session and subscription. The relay fans every matching event to all of them. Give each instance a distinct clientId. Producers and audit logs can then attribute them.
Reserve top-level segments as bounded domains: events, sensors, devices, fleet. The top-level segment maps to one underlying track. A small, stable set thus keeps fan-out coarse and predictable. + / # give you all the routing flexibility below it.

Where to go next

Details

Wire model, lanes/QoS, retained semantics, and the architecture.

SDK Methods

Every method, parameter, type, and event on the Data client.