@onlineapps/conn-orch-registry 1.1.37 → 1.1.39
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/package.json +2 -2
- package/src/queueManager.js +15 -4
- package/src/registryClient.js +37 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onlineapps/conn-orch-registry",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.39",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Connector-registry-client provides the core communication mechanism for microservices in this environment. It enables them to interact with a services_registry to receive and fulfill tasks by submitting heartbeats or their API descriptions.",
|
|
6
6
|
"keywords": [
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
41
|
"@onlineapps/conn-base-storage": "1.0.8",
|
|
42
|
-
"@onlineapps/mq-client-core": "1.0.
|
|
42
|
+
"@onlineapps/mq-client-core": "1.0.75",
|
|
43
43
|
"@onlineapps/runtime-config": "1.0.2",
|
|
44
44
|
"amqplib": "^0.10.9",
|
|
45
45
|
"axios": "^1.12.2",
|
package/src/queueManager.js
CHANGED
|
@@ -45,9 +45,10 @@ class QueueManager {
|
|
|
45
45
|
*/
|
|
46
46
|
async init() {
|
|
47
47
|
const CONNECT_TIMEOUT = 10000; // 10 seconds
|
|
48
|
+
let connectTimeout;
|
|
48
49
|
const connectPromise = amqp.connect(this.amqpUrl);
|
|
49
50
|
const connectTimeoutPromise = new Promise((_, reject) => {
|
|
50
|
-
setTimeout(() => {
|
|
51
|
+
connectTimeout = setTimeout(() => {
|
|
51
52
|
reject(new Error(`RabbitMQ connection timeout after ${CONNECT_TIMEOUT}ms. RabbitMQ may be unavailable at ${this.amqpUrl}`));
|
|
52
53
|
}, CONNECT_TIMEOUT);
|
|
53
54
|
});
|
|
@@ -56,14 +57,17 @@ class QueueManager {
|
|
|
56
57
|
this.conn = await Promise.race([connectPromise, connectTimeoutPromise]);
|
|
57
58
|
} catch (error) {
|
|
58
59
|
throw new Error(`[QueueManager] Failed to connect to RabbitMQ: ${error.message}`);
|
|
60
|
+
} finally {
|
|
61
|
+
if (connectTimeout) clearTimeout(connectTimeout);
|
|
59
62
|
}
|
|
60
63
|
|
|
61
64
|
// Use regular channel instead of ConfirmChannel to avoid RPC reply queue issues
|
|
62
65
|
// ConfirmChannel uses RPC pattern which requires reply queues that may not exist
|
|
63
66
|
const CHANNEL_TIMEOUT = 5000; // 5 seconds
|
|
67
|
+
let channelTimeout;
|
|
64
68
|
const channelPromise = this.conn.createChannel();
|
|
65
69
|
const channelTimeoutPromise = new Promise((_, reject) => {
|
|
66
|
-
setTimeout(() => {
|
|
70
|
+
channelTimeout = setTimeout(() => {
|
|
67
71
|
reject(new Error(`Channel creation timeout after ${CHANNEL_TIMEOUT}ms`));
|
|
68
72
|
}, CHANNEL_TIMEOUT);
|
|
69
73
|
});
|
|
@@ -78,6 +82,8 @@ class QueueManager {
|
|
|
78
82
|
// Ignore close errors
|
|
79
83
|
}
|
|
80
84
|
throw new Error(`[QueueManager] Failed to create channel: ${error.message}`);
|
|
85
|
+
} finally {
|
|
86
|
+
if (channelTimeout) clearTimeout(channelTimeout);
|
|
81
87
|
}
|
|
82
88
|
}
|
|
83
89
|
|
|
@@ -127,14 +133,19 @@ class QueueManager {
|
|
|
127
133
|
try {
|
|
128
134
|
const assertStartTime = Date.now();
|
|
129
135
|
const ASSERT_TIMEOUT = 5000; // 5 seconds
|
|
136
|
+
let assertTimeout;
|
|
130
137
|
const assertPromise = this.channel.assertQueue(q, queueOptions);
|
|
131
138
|
const assertTimeoutPromise = new Promise((_, reject) => {
|
|
132
|
-
setTimeout(() => {
|
|
139
|
+
assertTimeout = setTimeout(() => {
|
|
133
140
|
reject(new Error(`assertQueue timeout after ${ASSERT_TIMEOUT}ms`));
|
|
134
141
|
}, ASSERT_TIMEOUT);
|
|
135
142
|
});
|
|
136
143
|
|
|
137
|
-
|
|
144
|
+
try {
|
|
145
|
+
await Promise.race([assertPromise, assertTimeoutPromise]);
|
|
146
|
+
} finally {
|
|
147
|
+
if (assertTimeout) clearTimeout(assertTimeout);
|
|
148
|
+
}
|
|
138
149
|
const assertEndTime = Date.now();
|
|
139
150
|
console.log(`[QueueManager] [REGISTRY] [QUEUE] ✓ Queue ${q} asserted (took ${assertEndTime - assertStartTime}ms)`);
|
|
140
151
|
} catch (assertErr) {
|
package/src/registryClient.js
CHANGED
|
@@ -126,8 +126,9 @@ class ServiceRegistryClient extends EventEmitter {
|
|
|
126
126
|
},
|
|
127
127
|
{ noAck: false }
|
|
128
128
|
);
|
|
129
|
+
let consumeRegistryTimeout;
|
|
129
130
|
const consumeRegistryTimeoutPromise = new Promise((_, reject) => {
|
|
130
|
-
setTimeout(() => {
|
|
131
|
+
consumeRegistryTimeout = setTimeout(() => {
|
|
131
132
|
reject(new Error(`consume() timeout for ${this.serviceRegistryQueue} after ${CONSUME_TIMEOUT}ms`));
|
|
132
133
|
}, CONSUME_TIMEOUT);
|
|
133
134
|
});
|
|
@@ -138,6 +139,8 @@ class ServiceRegistryClient extends EventEmitter {
|
|
|
138
139
|
} catch (consumeErr) {
|
|
139
140
|
console.error(`[FÁZE 0.6] Consumer Startup - FAILED: ${consumeErr.message}`);
|
|
140
141
|
throw new Error(`[RegistryClient] ${this.serviceName}: Failed to start consumer on ${this.serviceRegistryQueue}: ${consumeErr.message}`);
|
|
142
|
+
} finally {
|
|
143
|
+
if (consumeRegistryTimeout) clearTimeout(consumeRegistryTimeout);
|
|
141
144
|
}
|
|
142
145
|
}
|
|
143
146
|
|
|
@@ -200,6 +203,13 @@ class ServiceRegistryClient extends EventEmitter {
|
|
|
200
203
|
if (this.pendingRegistrations && this.pendingRegistrations.has(payload.requestId)) {
|
|
201
204
|
console.log(`[RegistryClient] ${this.serviceName}: [REGISTRATION] Found matching pending registration, extracting resolve function...`);
|
|
202
205
|
const { resolve } = this.pendingRegistrations.get(payload.requestId);
|
|
206
|
+
|
|
207
|
+
// Clear associated timeout
|
|
208
|
+
if (this.pendingTimeouts && this.pendingTimeouts.has(payload.requestId)) {
|
|
209
|
+
clearTimeout(this.pendingTimeouts.get(payload.requestId));
|
|
210
|
+
this.pendingTimeouts.delete(payload.requestId);
|
|
211
|
+
}
|
|
212
|
+
|
|
203
213
|
this.pendingRegistrations.delete(payload.requestId);
|
|
204
214
|
console.log(`[RegistryClient] ${this.serviceName}: [REGISTRATION] ✓ Resolve function extracted, pending registration removed`);
|
|
205
215
|
|
|
@@ -308,8 +318,9 @@ class ServiceRegistryClient extends EventEmitter {
|
|
|
308
318
|
}
|
|
309
319
|
})();
|
|
310
320
|
|
|
321
|
+
let verifyTimeout;
|
|
311
322
|
const timeoutPromise = new Promise((_, reject) => {
|
|
312
|
-
setTimeout(() => {
|
|
323
|
+
verifyTimeout = setTimeout(() => {
|
|
313
324
|
reject(new Error(`[RegistryClient] ${this.serviceName}: Timeout verifying infrastructure queue '${queueName}' after ${QUEUE_VERIFY_TIMEOUT}ms. Queue may not exist or RabbitMQ is unresponsive.`));
|
|
314
325
|
}, QUEUE_VERIFY_TIMEOUT);
|
|
315
326
|
});
|
|
@@ -320,6 +331,8 @@ class ServiceRegistryClient extends EventEmitter {
|
|
|
320
331
|
// Clear verification cache on error so we can retry
|
|
321
332
|
this._verifiedInfraQueues.delete(queueName);
|
|
322
333
|
throw error;
|
|
334
|
+
} finally {
|
|
335
|
+
if (verifyTimeout) clearTimeout(verifyTimeout);
|
|
323
336
|
}
|
|
324
337
|
}
|
|
325
338
|
|
|
@@ -379,15 +392,19 @@ class ServiceRegistryClient extends EventEmitter {
|
|
|
379
392
|
const responsePromise = new Promise((resolve, reject) => {
|
|
380
393
|
// Store resolver for this registration request
|
|
381
394
|
this.pendingRegistrations = this.pendingRegistrations || new Map();
|
|
382
|
-
this.
|
|
395
|
+
this.pendingTimeouts = this.pendingTimeouts || new Map();
|
|
383
396
|
|
|
384
397
|
// Set timeout for registration response
|
|
385
|
-
setTimeout(() => {
|
|
398
|
+
const timeoutId = setTimeout(() => {
|
|
386
399
|
if (this.pendingRegistrations.has(msgId)) {
|
|
387
400
|
this.pendingRegistrations.delete(msgId);
|
|
401
|
+
this.pendingTimeouts.delete(msgId);
|
|
388
402
|
reject(new Error(`Registration timeout after ${timeout}ms - no response from registry`));
|
|
389
403
|
}
|
|
390
404
|
}, timeout);
|
|
405
|
+
|
|
406
|
+
this.pendingRegistrations.set(msgId, { resolve, reject });
|
|
407
|
+
this.pendingTimeouts.set(msgId, timeoutId);
|
|
391
408
|
});
|
|
392
409
|
|
|
393
410
|
// Initialize queueManager if not already initialized
|
|
@@ -671,9 +688,24 @@ class ServiceRegistryClient extends EventEmitter {
|
|
|
671
688
|
* @returns {Promise<void>}
|
|
672
689
|
*/
|
|
673
690
|
async close() {
|
|
691
|
+
// Clear all pending registration timeouts
|
|
692
|
+
if (this.pendingTimeouts) {
|
|
693
|
+
for (const timeoutId of this.pendingTimeouts.values()) {
|
|
694
|
+
clearTimeout(timeoutId);
|
|
695
|
+
}
|
|
696
|
+
this.pendingTimeouts.clear();
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
// Clear pending registrations (don't reject - client is closing)
|
|
700
|
+
if (this.pendingRegistrations) {
|
|
701
|
+
this.pendingRegistrations.clear();
|
|
702
|
+
}
|
|
703
|
+
|
|
674
704
|
this.stopHeartbeat();
|
|
675
705
|
if (this.eventConsumer) {
|
|
676
|
-
this.eventConsumer.clearCache
|
|
706
|
+
if (typeof this.eventConsumer.clearCache === 'function') {
|
|
707
|
+
this.eventConsumer.clearCache();
|
|
708
|
+
}
|
|
677
709
|
}
|
|
678
710
|
await this.queueManager.close();
|
|
679
711
|
}
|