Subscription Channels
Receive real-time node updates through a unified, priority-based channel system (SDK v2.2.2+).
For simple discovery and legacy callbacks, see Events and Subscriptions.
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
| Approach | Use when |
|---|---|
ESPRMUser.subscribe() | Local discovery, legacy node updates |
subscriptionManager | Multi-source updates with priority |
Best Practices
- Subscribe after login when nodes are loaded
- Set channel order before subscribing
- Call
dispose()on logout - Add custom channels only when needed
Related Resource
- API Reference: