@onlineapps/conn-infra-mq 1.1.7 → 1.1.8

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onlineapps/conn-infra-mq",
3
- "version": "1.1.7",
3
+ "version": "1.1.8",
4
4
  "description": "A promise-based, broker-agnostic client for sending and receiving messages via RabbitMQ",
5
5
  "main": "src/index.js",
6
6
  "repository": {
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
+