node-red-contrib-uos-nats 0.1.45 → 0.1.47
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/subjects.js +6 -0
- package/nodes/datahub-input.js +16 -9
- package/package.json +1 -1
package/lib/subjects.js
CHANGED
|
@@ -9,3 +9,9 @@ export function readVariablesQuery(providerId) {
|
|
|
9
9
|
export function providerDefinitionChanged(providerId) {
|
|
10
10
|
return `${VERSION_PREFIX}.${LOCATION_PREFIX}.${providerId}.def.evt.changed`;
|
|
11
11
|
}
|
|
12
|
+
export function registryProviderQuery(providerId) {
|
|
13
|
+
return `${VERSION_PREFIX}.${LOCATION_PREFIX}.registry.providers.${providerId}.def.qry.read`;
|
|
14
|
+
}
|
|
15
|
+
export function readProviderDefinitionQuery(providerId) {
|
|
16
|
+
return `${VERSION_PREFIX}.${LOCATION_PREFIX}.${providerId}.def.qry.read`;
|
|
17
|
+
}
|
package/nodes/datahub-input.js
CHANGED
|
@@ -140,17 +140,24 @@ module.exports = function (RED) {
|
|
|
140
140
|
// Retry Definition Fetch via NATS if Map is empty AND no manual defs
|
|
141
141
|
if (defMap.size === 0 && this.manualDefs.length === 0) {
|
|
142
142
|
try {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
// Importing payloads to use our new decode function
|
|
147
|
-
// Assuming payloads is already loaded above
|
|
148
|
-
|
|
143
|
+
// Strategy 1: Direct Provider Query (Standard for many providers)
|
|
144
|
+
this.warn(`Attempting NATS Discovery (Direct) for ${this.providerId}...`);
|
|
145
|
+
const defMsg = await nc.request(subjects.readProviderDefinitionQuery(this.providerId), new Uint8Array(0), { timeout: 1000 });
|
|
149
146
|
const defs = payloads.decodeProviderDefinition(defMsg.data);
|
|
150
|
-
this.warn(`NATS
|
|
147
|
+
this.warn(`NATS Direct Discovery: Loaded ${defs.length} variables.`);
|
|
151
148
|
defs.forEach((def) => defMap.set(def.id, def));
|
|
152
|
-
} catch (
|
|
153
|
-
|
|
149
|
+
} catch (firstErr) {
|
|
150
|
+
// Strategy 2: Registry Query (Central lookup, often requires different perms or used by Hub)
|
|
151
|
+
try {
|
|
152
|
+
this.warn(`NATS Direct failed (${firstErr.message}), trying Registry Discovery...`);
|
|
153
|
+
// Note: 'registryProviderQuery' accesses the central registry which might proxy the definition
|
|
154
|
+
const regMsg = await nc.request(subjects.registryProviderQuery(this.providerId), new Uint8Array(0), { timeout: 2000 });
|
|
155
|
+
const defs = payloads.decodeProviderDefinition(regMsg.data);
|
|
156
|
+
this.warn(`NATS Registry Discovery: Loaded ${defs.length} variables.`);
|
|
157
|
+
defs.forEach((def) => defMap.set(def.id, def));
|
|
158
|
+
} catch (secondErr) {
|
|
159
|
+
this.warn(`All Discovery methods failed (REST, NATS Direct, NATS Registry). Please use Manual Definitions (Name:ID). Error: ${secondErr.message}`);
|
|
160
|
+
}
|
|
154
161
|
}
|
|
155
162
|
}
|
|
156
163
|
|