@onlineapps/conn-infra-mq 1.1.45 → 1.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/package.json
CHANGED
|
@@ -36,6 +36,14 @@ class QueueManager {
|
|
|
36
36
|
if (!transport || !transport.channel) {
|
|
37
37
|
throw new Error('MQ client not connected');
|
|
38
38
|
}
|
|
39
|
+
|
|
40
|
+
// CRITICAL: Business queues MUST be created via setupServiceQueues() AFTER registration
|
|
41
|
+
// Business queues should NOT be created via ensureQueue() before registration
|
|
42
|
+
// This prevents queues from being created with wrong arguments or before service is registered
|
|
43
|
+
if (queueConfig.isBusinessQueue(queueName)) {
|
|
44
|
+
throw new Error(`Business queue ${queueName} must be created via setupServiceQueues() after successful registration. Do not use ensureQueue() for business queues.`);
|
|
45
|
+
}
|
|
46
|
+
|
|
39
47
|
// Use queueChannel for queue operations to avoid RPC reply queue issues
|
|
40
48
|
// queueChannel is a regular channel, not ConfirmChannel
|
|
41
49
|
const channel = transport.queueChannel || transport.channel;
|
|
@@ -55,25 +63,6 @@ class QueueManager {
|
|
|
55
63
|
console.warn(`[QueueManager] Infrastructure queue config not found for ${queueName}, using provided options:`, error.message);
|
|
56
64
|
queueOptions = this._buildQueueOptions(queueName, options);
|
|
57
65
|
}
|
|
58
|
-
} else if (queueConfig.isBusinessQueue(queueName)) {
|
|
59
|
-
// Business queue - use central business queue config
|
|
60
|
-
try {
|
|
61
|
-
const parsed = queueConfig.parseBusinessQueue(queueName);
|
|
62
|
-
if (parsed) {
|
|
63
|
-
const businessConfig = queueConfig.getBusinessQueueConfig(parsed.queueType, parsed.serviceName);
|
|
64
|
-
queueOptions = {
|
|
65
|
-
durable: businessConfig.durable !== false,
|
|
66
|
-
arguments: { ...businessConfig.arguments }
|
|
67
|
-
};
|
|
68
|
-
} else {
|
|
69
|
-
// Fallback to provided options
|
|
70
|
-
queueOptions = this._buildQueueOptions(queueName, options);
|
|
71
|
-
}
|
|
72
|
-
} catch (error) {
|
|
73
|
-
// If config not found, fall back to provided options
|
|
74
|
-
console.warn(`[QueueManager] Business queue config not found for ${queueName}, using provided options:`, error.message);
|
|
75
|
-
queueOptions = this._buildQueueOptions(queueName, options);
|
|
76
|
-
}
|
|
77
66
|
} else {
|
|
78
67
|
// Unknown queue type - use provided options
|
|
79
68
|
queueOptions = this._buildQueueOptions(queueName, options);
|
|
@@ -211,23 +211,34 @@ class RabbitMQClient extends EventEmitter {
|
|
|
211
211
|
try {
|
|
212
212
|
// Ensure queue exists if publishing directly to queue and using default exchange
|
|
213
213
|
if (!exchange) {
|
|
214
|
-
// CRITICAL: For business queues, do NOT use checkQueue() - it closes channel on 404!
|
|
215
|
-
// Business queues should already be created by setupServiceQueues() BEFORE publish is called
|
|
216
|
-
// If queue doesn't exist, that's a programming error - just proceed to publish
|
|
217
|
-
// publish() will fail with a clear error if queue doesn't exist
|
|
218
214
|
const isBusinessQueue = queueConfig.isBusinessQueue(queue);
|
|
219
215
|
|
|
220
216
|
if (isBusinessQueue) {
|
|
221
|
-
// Business
|
|
222
|
-
|
|
217
|
+
// CRITICAL: Business queues MUST exist before publish
|
|
218
|
+
// sendToQueue() automatically creates queue with DEFAULT arguments if it doesn't exist
|
|
219
|
+
// This would create queue with wrong TTL, no DLQ, etc. - we MUST prevent this!
|
|
220
|
+
// Business queues must be created via setupServiceQueues() AFTER registration
|
|
221
|
+
// Use queueChannel (regular channel) to check existence without closing channel on 404
|
|
222
|
+
try {
|
|
223
|
+
await this._queueChannel.checkQueue(queue);
|
|
224
|
+
// Queue exists - safe to publish
|
|
225
|
+
console.log(`[RabbitMQClient] ✓ Business queue ${queue} exists, publishing...`);
|
|
226
|
+
} catch (checkErr) {
|
|
227
|
+
if (checkErr.code === 404) {
|
|
228
|
+
// Queue doesn't exist - this is a programming error
|
|
229
|
+
// Business queue should have been created by setupServiceQueues() after registration
|
|
230
|
+
throw new Error(`Business queue '${queue}' does not exist. Queue must be created via setupServiceQueues() AFTER successful registration. Cannot publish to non-existent business queue (would create it with wrong arguments).`);
|
|
231
|
+
}
|
|
232
|
+
// Other error - rethrow
|
|
233
|
+
throw checkErr;
|
|
234
|
+
}
|
|
223
235
|
} else {
|
|
224
|
-
// Infrastructure queue -
|
|
225
|
-
//
|
|
226
|
-
|
|
227
|
-
// This matches the pattern used for business queues - early creation, no runtime checks
|
|
228
|
-
console.log(`[RabbitMQClient] DEBUG: Infrastructure queue ${queue}, skipping assertQueue() - queue should already exist (created by monitoring consumer)`);
|
|
236
|
+
// Infrastructure queue - should already exist, created by infrastructure initialization
|
|
237
|
+
// If queue doesn't exist, that's an infrastructure problem
|
|
238
|
+
console.log(`[RabbitMQClient] DEBUG: Infrastructure queue ${queue}, assuming it exists (created by infrastructure initialization)`);
|
|
229
239
|
}
|
|
230
240
|
// Publish using ConfirmChannel (for publisher confirms)
|
|
241
|
+
// Queue exists, so sendToQueue() won't create it with wrong arguments
|
|
231
242
|
this._channel.sendToQueue(queue, buffer, { persistent, headers, routingKey });
|
|
232
243
|
} else {
|
|
233
244
|
// If exchange is specified, assert exchange and publish to it
|