@onlineapps/conn-orch-registry 1.1.21 → 1.1.22
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 +1 -1
- package/src/queueManager.js +52 -4
- package/src/registryClient.js +107 -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.22",
|
|
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": [
|
package/src/queueManager.js
CHANGED
|
@@ -19,6 +19,15 @@
|
|
|
19
19
|
*/
|
|
20
20
|
|
|
21
21
|
const amqp = require('amqplib');
|
|
22
|
+
// CRITICAL: Import queueConfig to ensure consistent queue parameters
|
|
23
|
+
// This prevents 406 PRECONDITION-FAILED errors from TTL mismatches
|
|
24
|
+
let queueConfig;
|
|
25
|
+
try {
|
|
26
|
+
queueConfig = require('@onlineapps/conn-infra-mq/src/config/queueConfig');
|
|
27
|
+
} catch (err) {
|
|
28
|
+
console.warn('[QueueManager] [REGISTRY] queueConfig not available, using defaults:', err.message);
|
|
29
|
+
queueConfig = null;
|
|
30
|
+
}
|
|
22
31
|
|
|
23
32
|
/**
|
|
24
33
|
* Queue manager for the microservice connector.
|
|
@@ -67,19 +76,58 @@ class QueueManager {
|
|
|
67
76
|
const queuesToCreate = baseQueues.concat(additionalQueues);
|
|
68
77
|
|
|
69
78
|
for (const q of queuesToCreate) {
|
|
79
|
+
console.log(`[QueueManager] [REGISTRY] [QUEUE] Ensuring queue: ${q} at ${new Date().toISOString()}`);
|
|
80
|
+
|
|
81
|
+
// CRITICAL: Use queueConfig.js to get correct parameters (TTL, max-length, etc.)
|
|
82
|
+
// This prevents 406 PRECONDITION-FAILED errors from TTL mismatches
|
|
83
|
+
let queueOptions = { durable: true };
|
|
84
|
+
|
|
85
|
+
if (queueConfig) {
|
|
86
|
+
try {
|
|
87
|
+
if (queueConfig.isInfrastructureQueue(q)) {
|
|
88
|
+
const infraConfig = queueConfig.getInfrastructureQueueConfig(q);
|
|
89
|
+
queueOptions = {
|
|
90
|
+
durable: infraConfig.durable !== false,
|
|
91
|
+
arguments: { ...infraConfig.arguments }
|
|
92
|
+
};
|
|
93
|
+
console.log(`[QueueManager] [REGISTRY] [QUEUE] Using infrastructure queue config for ${q}:`, JSON.stringify(queueOptions));
|
|
94
|
+
} else {
|
|
95
|
+
console.warn(`[QueueManager] [REGISTRY] [QUEUE] Queue ${q} is not an infrastructure queue, using default options`);
|
|
96
|
+
}
|
|
97
|
+
} catch (configErr) {
|
|
98
|
+
console.warn(`[QueueManager] [REGISTRY] [QUEUE] Failed to get config for ${q}, using defaults:`, configErr.message);
|
|
99
|
+
}
|
|
100
|
+
} else {
|
|
101
|
+
console.warn(`[QueueManager] [REGISTRY] [QUEUE] queueConfig not available, using default options for ${q}`);
|
|
102
|
+
}
|
|
103
|
+
|
|
70
104
|
// Use checkQueue first to avoid 406 PRECONDITION-FAILED closing the channel
|
|
71
|
-
// If queue doesn't exist (404), then assertQueue to create it
|
|
105
|
+
// If queue doesn't exist (404), then assertQueue to create it with correct options
|
|
72
106
|
try {
|
|
107
|
+
const checkStartTime = Date.now();
|
|
73
108
|
await this.channel.checkQueue(q);
|
|
109
|
+
const checkEndTime = Date.now();
|
|
110
|
+
console.log(`[QueueManager] [REGISTRY] [QUEUE] ✓ Queue ${q} exists (checkQueue took ${checkEndTime - checkStartTime}ms)`);
|
|
74
111
|
// Queue exists - continue
|
|
75
112
|
} catch (checkErr) {
|
|
76
|
-
// If queue doesn't exist (404), create it with
|
|
113
|
+
// If queue doesn't exist (404), create it with correct options from queueConfig
|
|
77
114
|
if (checkErr.code === 404) {
|
|
78
|
-
|
|
115
|
+
console.log(`[QueueManager] [REGISTRY] [QUEUE] Queue ${q} does not exist (404), creating with options:`, JSON.stringify(queueOptions));
|
|
116
|
+
const assertStartTime = Date.now();
|
|
117
|
+
try {
|
|
118
|
+
await this.channel.assertQueue(q, queueOptions);
|
|
119
|
+
const assertEndTime = Date.now();
|
|
120
|
+
console.log(`[QueueManager] [REGISTRY] [QUEUE] ✓ Created queue ${q} (assertQueue took ${assertEndTime - assertStartTime}ms)`);
|
|
121
|
+
} catch (assertErr) {
|
|
122
|
+
console.error(`[QueueManager] [REGISTRY] [QUEUE] ✗ Failed to create queue ${q}:`, assertErr.message);
|
|
123
|
+
console.error(`[QueueManager] [REGISTRY] [QUEUE] Error code: ${assertErr.code}`);
|
|
124
|
+
throw assertErr;
|
|
125
|
+
}
|
|
79
126
|
} else {
|
|
80
127
|
// Other error (including 406) - queue exists with different args
|
|
81
128
|
// Log warning and continue without asserting
|
|
82
|
-
console.warn(`[QueueManager] Queue ${q} exists with different arguments, using as-is:`, checkErr.message);
|
|
129
|
+
console.warn(`[QueueManager] [REGISTRY] [QUEUE] Queue ${q} exists with different arguments, using as-is:`, checkErr.message);
|
|
130
|
+
console.warn(`[QueueManager] [REGISTRY] [QUEUE] Error code: ${checkErr.code}`);
|
|
83
131
|
}
|
|
84
132
|
}
|
|
85
133
|
}
|
package/src/registryClient.js
CHANGED
|
@@ -20,6 +20,46 @@ const QueueManager = require('./queueManager');
|
|
|
20
20
|
const RegistryEventConsumer = require('./registryEventConsumer');
|
|
21
21
|
const { v4: uuidv4 } = require('uuid');
|
|
22
22
|
|
|
23
|
+
// CRITICAL: Import queueConfig to ensure consistent queue parameters
|
|
24
|
+
// This prevents 406 PRECONDITION-FAILED errors from TTL mismatches
|
|
25
|
+
let queueConfig;
|
|
26
|
+
try {
|
|
27
|
+
queueConfig = require('@onlineapps/conn-infra-mq/src/config/queueConfig');
|
|
28
|
+
} catch (err) {
|
|
29
|
+
console.warn('[RegistryClient] queueConfig not available, using defaults:', err.message);
|
|
30
|
+
queueConfig = null;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Helper function to get queue options from queueConfig.js
|
|
35
|
+
* @param {string} queueName - Queue name
|
|
36
|
+
* @returns {Object} Queue options with correct parameters (TTL, max-length, etc.)
|
|
37
|
+
*/
|
|
38
|
+
function getQueueOptions(queueName) {
|
|
39
|
+
let queueOptions = { durable: true };
|
|
40
|
+
|
|
41
|
+
if (queueConfig) {
|
|
42
|
+
try {
|
|
43
|
+
if (queueConfig.isInfrastructureQueue(queueName)) {
|
|
44
|
+
const infraConfig = queueConfig.getInfrastructureQueueConfig(queueName);
|
|
45
|
+
queueOptions = {
|
|
46
|
+
durable: infraConfig.durable !== false,
|
|
47
|
+
arguments: { ...infraConfig.arguments }
|
|
48
|
+
};
|
|
49
|
+
console.log(`[RegistryClient] [QUEUE] Using infrastructure queue config for ${queueName}:`, JSON.stringify(queueOptions));
|
|
50
|
+
} else {
|
|
51
|
+
console.warn(`[RegistryClient] [QUEUE] Queue ${queueName} is not an infrastructure queue, using default options`);
|
|
52
|
+
}
|
|
53
|
+
} catch (configErr) {
|
|
54
|
+
console.warn(`[RegistryClient] [QUEUE] Failed to get config for ${queueName}, using defaults:`, configErr.message);
|
|
55
|
+
}
|
|
56
|
+
} else {
|
|
57
|
+
console.warn(`[RegistryClient] [QUEUE] queueConfig not available, using default options for ${queueName}`);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return queueOptions;
|
|
61
|
+
}
|
|
62
|
+
|
|
23
63
|
class ServiceRegistryClient extends EventEmitter {
|
|
24
64
|
/**
|
|
25
65
|
* @param {Object} opts
|
|
@@ -81,6 +121,13 @@ class ServiceRegistryClient extends EventEmitter {
|
|
|
81
121
|
// Ensure existence of API, registry and service response queues
|
|
82
122
|
await this.queueManager.ensureQueues([this.apiQueue, this.registryQueue, this.serviceResponseQueue, this.serviceRegistryQueue]);
|
|
83
123
|
|
|
124
|
+
// CRITICAL: Before consume(), we must assertQueue with correct parameters
|
|
125
|
+
// amqplib's channel.consume() may internally call assertQueue() WITHOUT parameters
|
|
126
|
+
// This causes 406 PRECONDITION-FAILED if queue exists with different arguments
|
|
127
|
+
console.log(`[RegistryClient] [CONSUMER] About to consume from ${this.serviceResponseQueue}`);
|
|
128
|
+
console.log(`[RegistryClient] [CONSUMER] ⚠ WARNING: amqplib's channel.consume() may internally call assertQueue() WITHOUT parameters`);
|
|
129
|
+
console.log(`[RegistryClient] [CONSUMER] ⚠ WARNING: Queue should already be asserted by ensureQueues() above with correct parameters from queueConfig.js`);
|
|
130
|
+
|
|
84
131
|
// Start consuming service response queue for registry responses
|
|
85
132
|
await this.queueManager.channel.consume(
|
|
86
133
|
this.serviceResponseQueue,
|
|
@@ -96,6 +143,10 @@ class ServiceRegistryClient extends EventEmitter {
|
|
|
96
143
|
);
|
|
97
144
|
|
|
98
145
|
// CRITICAL: Also listen on registry event queue for certificate delivery
|
|
146
|
+
console.log(`[RegistryClient] [CONSUMER] About to consume from ${this.serviceRegistryQueue}`);
|
|
147
|
+
console.log(`[RegistryClient] [CONSUMER] ⚠ WARNING: amqplib's channel.consume() may internally call assertQueue() WITHOUT parameters`);
|
|
148
|
+
console.log(`[RegistryClient] [CONSUMER] ⚠ WARNING: Queue should already be asserted by ensureQueues() above with correct parameters from queueConfig.js`);
|
|
149
|
+
|
|
99
150
|
await this.queueManager.channel.consume(
|
|
100
151
|
this.serviceRegistryQueue,
|
|
101
152
|
msg => {
|
|
@@ -263,14 +314,38 @@ class ServiceRegistryClient extends EventEmitter {
|
|
|
263
314
|
}
|
|
264
315
|
|
|
265
316
|
// Send registration message to registry
|
|
317
|
+
// CRITICAL: Use queueConfig.js to get correct parameters (TTL, max-length, etc.)
|
|
318
|
+
// This prevents 406 PRECONDITION-FAILED errors from TTL mismatches
|
|
319
|
+
console.log(`[RegistryClient] [PUBLISH] Preparing to publish to ${this.registryQueue}`);
|
|
320
|
+
|
|
321
|
+
let queueOptions = { durable: true };
|
|
322
|
+
try {
|
|
323
|
+
const queueConfig = require('@onlineapps/conn-infra-mq/src/config/queueConfig');
|
|
324
|
+
if (queueConfig.isInfrastructureQueue(this.registryQueue)) {
|
|
325
|
+
const infraConfig = queueConfig.getInfrastructureQueueConfig(this.registryQueue);
|
|
326
|
+
queueOptions = {
|
|
327
|
+
durable: infraConfig.durable !== false,
|
|
328
|
+
arguments: { ...infraConfig.arguments }
|
|
329
|
+
};
|
|
330
|
+
console.log(`[RegistryClient] [PUBLISH] Using infrastructure queue config for ${this.registryQueue}:`, JSON.stringify(queueOptions));
|
|
331
|
+
}
|
|
332
|
+
} catch (configErr) {
|
|
333
|
+
console.warn(`[RegistryClient] [PUBLISH] Failed to get config for ${this.registryQueue}, using defaults:`, configErr.message);
|
|
334
|
+
}
|
|
335
|
+
|
|
266
336
|
// Use checkQueue to avoid 406 PRECONDITION-FAILED closing the channel
|
|
267
337
|
try {
|
|
268
338
|
await this.queueManager.channel.checkQueue(this.registryQueue);
|
|
339
|
+
console.log(`[RegistryClient] [PUBLISH] ✓ Queue ${this.registryQueue} exists`);
|
|
269
340
|
} catch (checkErr) {
|
|
270
341
|
if (checkErr.code === 404) {
|
|
271
|
-
|
|
342
|
+
console.log(`[RegistryClient] [PUBLISH] Queue ${this.registryQueue} does not exist (404), creating with options:`, JSON.stringify(queueOptions));
|
|
343
|
+
await this.queueManager.channel.assertQueue(this.registryQueue, queueOptions);
|
|
344
|
+
console.log(`[RegistryClient] [PUBLISH] ✓ Created queue ${this.registryQueue}`);
|
|
345
|
+
} else {
|
|
346
|
+
console.warn(`[RegistryClient] [PUBLISH] Queue ${this.registryQueue} exists with different arguments:`, checkErr.message);
|
|
347
|
+
// If 406 or other error, queue exists - proceed to publish
|
|
272
348
|
}
|
|
273
|
-
// If 406 or other error, queue exists - proceed to publish
|
|
274
349
|
}
|
|
275
350
|
console.log(`[RegistryClient] ${this.serviceName}: Sending registration message to queue: ${this.registryQueue}`);
|
|
276
351
|
console.log(`[RegistryClient] ${this.serviceName}: Message type: ${msg.type}, serviceName: ${msg.serviceName}, version: ${msg.version}`);
|
|
@@ -311,12 +386,21 @@ class ServiceRegistryClient extends EventEmitter {
|
|
|
311
386
|
};
|
|
312
387
|
|
|
313
388
|
// Send deregistration message to registry
|
|
389
|
+
// CRITICAL: Use queueConfig.js to get correct parameters (TTL, max-length, etc.)
|
|
390
|
+
console.log(`[RegistryClient] [PUBLISH] Preparing to publish to ${this.registryQueue} (deregister)`);
|
|
391
|
+
const queueOptions = getQueueOptions(this.registryQueue);
|
|
392
|
+
|
|
314
393
|
// Use checkQueue to avoid 406 PRECONDITION-FAILED closing the channel
|
|
315
394
|
try {
|
|
316
395
|
await this.queueManager.channel.checkQueue(this.registryQueue);
|
|
396
|
+
console.log(`[RegistryClient] [PUBLISH] ✓ Queue ${this.registryQueue} exists`);
|
|
317
397
|
} catch (checkErr) {
|
|
318
398
|
if (checkErr.code === 404) {
|
|
319
|
-
|
|
399
|
+
console.log(`[RegistryClient] [PUBLISH] Queue ${this.registryQueue} does not exist (404), creating with options:`, JSON.stringify(queueOptions));
|
|
400
|
+
await this.queueManager.channel.assertQueue(this.registryQueue, queueOptions);
|
|
401
|
+
console.log(`[RegistryClient] [PUBLISH] ✓ Created queue ${this.registryQueue}`);
|
|
402
|
+
} else {
|
|
403
|
+
console.warn(`[RegistryClient] [PUBLISH] Queue ${this.registryQueue} exists with different arguments:`, checkErr.message);
|
|
320
404
|
}
|
|
321
405
|
}
|
|
322
406
|
this.queueManager.channel.sendToQueue(
|
|
@@ -361,12 +445,21 @@ class ServiceRegistryClient extends EventEmitter {
|
|
|
361
445
|
specificationEndpoint: this.specificationEndpoint,
|
|
362
446
|
timestamp: new Date().toISOString()
|
|
363
447
|
};
|
|
448
|
+
// CRITICAL: Use queueConfig.js to get correct parameters (TTL, max-length, etc.)
|
|
449
|
+
console.log(`[RegistryClient] [PUBLISH] Preparing to publish to ${this.registryQueue} (heartbeat)`);
|
|
450
|
+
const queueOptions = getQueueOptions(this.registryQueue);
|
|
451
|
+
|
|
364
452
|
// Use checkQueue to avoid 406 PRECONDITION-FAILED closing the channel
|
|
365
453
|
try {
|
|
366
454
|
await this.queueManager.channel.checkQueue(this.registryQueue);
|
|
455
|
+
console.log(`[RegistryClient] [PUBLISH] ✓ Queue ${this.registryQueue} exists`);
|
|
367
456
|
} catch (checkErr) {
|
|
368
457
|
if (checkErr.code === 404) {
|
|
369
|
-
|
|
458
|
+
console.log(`[RegistryClient] [PUBLISH] Queue ${this.registryQueue} does not exist (404), creating with options:`, JSON.stringify(queueOptions));
|
|
459
|
+
await this.queueManager.channel.assertQueue(this.registryQueue, queueOptions);
|
|
460
|
+
console.log(`[RegistryClient] [PUBLISH] ✓ Created queue ${this.registryQueue}`);
|
|
461
|
+
} else {
|
|
462
|
+
console.warn(`[RegistryClient] [PUBLISH] Queue ${this.registryQueue} exists with different arguments:`, checkErr.message);
|
|
370
463
|
}
|
|
371
464
|
}
|
|
372
465
|
this.queueManager.channel.sendToQueue(
|
|
@@ -412,12 +505,21 @@ class ServiceRegistryClient extends EventEmitter {
|
|
|
412
505
|
description: apiDescription,
|
|
413
506
|
timestamp: new Date().toISOString()
|
|
414
507
|
};
|
|
508
|
+
// CRITICAL: Use queueConfig.js to get correct parameters (TTL, max-length, etc.)
|
|
509
|
+
console.log(`[RegistryClient] [PUBLISH] Preparing to publish to ${this.registryQueue} (apiDescription)`);
|
|
510
|
+
const queueOptions = getQueueOptions(this.registryQueue);
|
|
511
|
+
|
|
415
512
|
// Use checkQueue to avoid 406 PRECONDITION-FAILED closing the channel
|
|
416
513
|
try {
|
|
417
514
|
await this.queueManager.channel.checkQueue(this.registryQueue);
|
|
515
|
+
console.log(`[RegistryClient] [PUBLISH] ✓ Queue ${this.registryQueue} exists`);
|
|
418
516
|
} catch (checkErr) {
|
|
419
517
|
if (checkErr.code === 404) {
|
|
420
|
-
|
|
518
|
+
console.log(`[RegistryClient] [PUBLISH] Queue ${this.registryQueue} does not exist (404), creating with options:`, JSON.stringify(queueOptions));
|
|
519
|
+
await this.queueManager.channel.assertQueue(this.registryQueue, queueOptions);
|
|
520
|
+
console.log(`[RegistryClient] [PUBLISH] ✓ Created queue ${this.registryQueue}`);
|
|
521
|
+
} else {
|
|
522
|
+
console.warn(`[RegistryClient] [PUBLISH] Queue ${this.registryQueue} exists with different arguments:`, checkErr.message);
|
|
421
523
|
}
|
|
422
524
|
}
|
|
423
525
|
this.queueManager.channel.sendToQueue(
|