Skip to main content

Subscription Channels

Receive real-time node updates through a unified, priority-based channel system (SDK v2.2.2+).

info

For simple discovery and legacy callbacks, see Events and Subscriptions.

note

A notification adapter is required for the built-in notification channel.

What This Module Does ?​

ESPRMBase.subscriptionManager coordinates updates from multiple sources (push, MQTT, custom channels) and delivers them through one callback with priority-based fallback.

Use this when updates may arrive from several transports and you need a unified pipeline. Use Events and Subscriptions for local discovery only or simple ESPRMUser.subscribe() fan-out.

Expected outcome: Updates arrive as ESPNodeUpdateData from the highest-priority channel that succeeds per node.

Common Workflows​

Subscribe to all nodes after login​

import { ESPRMBase } from "@espressif/rainmaker-base-sdk";

const { nodes } = await userInstance.getUserNodes();

await ESPRMBase.subscriptionManager.subscribeToAllNodes(nodes, (update) => {
console.log(`Node ${update.nodeId} via ${update.source}`);
refreshNodeUI(update.nodeId, update.payload);
});

Subscribe to one node​

await ESPRMBase.subscriptionManager.subscribeToNode(node, handleUpdate);

Set global channel priority​

ESPRMBase.subscriptionManager.setGlobalChannelOrder(["notification", "mqtt"]);

Per-node priority override​

node.setSubscriptionChannelOrder(["mqtt", "notification"]);
node.clearSubscriptionChannelOrder();

Register a custom channel​

class MyMqttChannel {
channelId = "mqtt";
async initialize() {}
supportsNode(node) { return true; }
async subscribe(node, callback) { return true; }
async unsubscribe(node) {}
async dispose() {}
}

await ESPRMBase.subscriptionManager.registerChannel(new MyMqttChannel());

Cleanup​

await ESPRMBase.subscriptionManager.unsubscribeFromNode(node.id);
await ESPRMBase.subscriptionManager.dispose();

Error Handling​

If no channel subscribes for a node, updates for that node are not delivered. Register at least one channel that supports the target node.

Advanced Concepts​

Architecture​

Priority resolution​

Events API vs subscription manager​

ApproachUse when
ESPRMUser.subscribe()Local discovery, legacy node updates
subscriptionManagerMulti-source updates with priority

Best Practices​

  1. Subscribe after login when nodes are loaded
  2. Set channel order before subscribing
  3. Call dispose() on logout
  4. Add custom channels only when needed

On this page