@onlineapps/conn-infra-mq 1.1.7 → 1.1.9
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
CHANGED
package/src/ConnectorMQClient.js
CHANGED
|
@@ -92,12 +92,20 @@ class ConnectorMQClient extends BaseClient {
|
|
|
92
92
|
}
|
|
93
93
|
|
|
94
94
|
// Setup service queues if service name provided
|
|
95
|
-
|
|
95
|
+
const shouldAutoSetup = this._config.autoSetupServiceQueues !== false;
|
|
96
|
+
|
|
97
|
+
if (this.serviceName !== 'unknown' && shouldAutoSetup) {
|
|
96
98
|
try {
|
|
97
99
|
await this.queues.setupServiceQueues(this.serviceName);
|
|
98
100
|
} catch (error) {
|
|
99
101
|
console.warn(`Failed to setup service queues: ${error.message}`);
|
|
100
102
|
}
|
|
103
|
+
} else if (this.serviceName !== 'unknown' && !shouldAutoSetup) {
|
|
104
|
+
if (this._config.logger && typeof this._config.logger.info === 'function') {
|
|
105
|
+
this._config.logger.info(`[ConnectorMQClient] Auto queue setup disabled for ${this.serviceName} (will be created explicitly)`);
|
|
106
|
+
} else {
|
|
107
|
+
console.log(`[ConnectorMQClient] Auto queue setup disabled for ${this.serviceName} (will be created explicitly)`);
|
|
108
|
+
}
|
|
101
109
|
}
|
|
102
110
|
|
|
103
111
|
this._initialized = true;
|
package/src/index.js
CHANGED
|
@@ -37,6 +37,11 @@ module.exports.layers = {
|
|
|
37
37
|
RetryHandler
|
|
38
38
|
};
|
|
39
39
|
|
|
40
|
+
// Export utilities
|
|
41
|
+
module.exports.utils = {
|
|
42
|
+
initInfrastructureQueues: require('./utils/initInfrastructureQueues').initInfrastructureQueues
|
|
43
|
+
};
|
|
44
|
+
|
|
40
45
|
// Backwards compatibility - MQWrapper points to ConnectorMQClient
|
|
41
46
|
module.exports.MQWrapper = ConnectorMQClient;
|
|
42
47
|
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* initInfrastructureQueues.js
|
|
5
|
+
*
|
|
6
|
+
* Unified tool for creating all infrastructure queues.
|
|
7
|
+
* Used by ALL relevant services (infrastructure AND business) during startup.
|
|
8
|
+
*
|
|
9
|
+
* Ensures consistent queue parameters across all services.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
const queueConfig = require('../config/queueConfig');
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Initialize all infrastructure queues
|
|
16
|
+
* @param {Object} channel - RabbitMQ channel
|
|
17
|
+
* @param {Object} options - Options
|
|
18
|
+
* @param {Array<string>} [options.queues] - Specific queues to create (default: all infrastructure queues)
|
|
19
|
+
* @param {Object} [options.logger] - Logger instance (default: console)
|
|
20
|
+
* @returns {Promise<void>}
|
|
21
|
+
*/
|
|
22
|
+
async function initInfrastructureQueues(channel, options = {}) {
|
|
23
|
+
const logger = options.logger || console;
|
|
24
|
+
const queuesToCreate = options.queues || [
|
|
25
|
+
// Workflow infrastructure queues
|
|
26
|
+
'workflow.init',
|
|
27
|
+
'workflow.completed',
|
|
28
|
+
'workflow.failed',
|
|
29
|
+
'workflow.dlq',
|
|
30
|
+
// Registry infrastructure queues
|
|
31
|
+
'registry.register',
|
|
32
|
+
'registry.heartbeats'
|
|
33
|
+
];
|
|
34
|
+
|
|
35
|
+
logger.log(`[QueueInit] Initializing ${queuesToCreate.length} infrastructure queues...`);
|
|
36
|
+
|
|
37
|
+
for (const queueName of queuesToCreate) {
|
|
38
|
+
try {
|
|
39
|
+
// Verify it's an infrastructure queue
|
|
40
|
+
if (!queueConfig.isInfrastructureQueue(queueName)) {
|
|
41
|
+
logger.warn(`[QueueInit] Skipping ${queueName} - not an infrastructure queue`);
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Get unified configuration
|
|
46
|
+
const config = queueConfig.getInfrastructureQueueConfig(queueName);
|
|
47
|
+
|
|
48
|
+
// Create queue with unified config
|
|
49
|
+
await channel.assertQueue(queueName, {
|
|
50
|
+
durable: config.durable !== false,
|
|
51
|
+
arguments: { ...config.arguments }
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
logger.log(`[QueueInit] ✓ Created infrastructure queue: ${queueName}`);
|
|
55
|
+
} catch (error) {
|
|
56
|
+
// If queue exists with different args (406), log warning but continue
|
|
57
|
+
if (error.code === 406) {
|
|
58
|
+
logger.warn(`[QueueInit] ⚠ Queue ${queueName} exists with different arguments - using as-is`);
|
|
59
|
+
} else {
|
|
60
|
+
logger.error(`[QueueInit] ✗ Failed to create ${queueName}:`, error.message);
|
|
61
|
+
throw error;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
logger.log(`[QueueInit] Infrastructure queues initialization complete`);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
module.exports = {
|
|
70
|
+
initInfrastructureQueues
|
|
71
|
+
};
|
|
72
|
+
|