@onlineapps/conn-infra-mq 1.1.28 → 1.1.30
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/layers/QueueManager.js +48 -11
- package/src/transports/rabbitmqClient.js +23 -13
package/package.json
CHANGED
|
@@ -336,25 +336,62 @@ class QueueManager {
|
|
|
336
336
|
}
|
|
337
337
|
|
|
338
338
|
// Setup DLQ exchange and bindings
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
339
|
+
console.log(`[QueueManager] DEBUG: Setting up DLQ exchange: ${this.config.dlxExchange}`);
|
|
340
|
+
console.log(`[QueueManager] DEBUG: Channel state before assertExchange: closed=${channel.closed}`);
|
|
341
|
+
|
|
342
|
+
try {
|
|
343
|
+
await channel.assertExchange(this.config.dlxExchange, 'direct', {
|
|
344
|
+
durable: true
|
|
345
|
+
});
|
|
346
|
+
console.log(`[QueueManager] DEBUG: DLQ exchange asserted, channel closed=${channel.closed}`);
|
|
347
|
+
} catch (exErr) {
|
|
348
|
+
console.error(`[QueueManager] DEBUG: assertExchange failed:`, exErr.message);
|
|
349
|
+
if (!channel || channel.closed) {
|
|
350
|
+
throw new Error(`Channel closed during assertExchange for ${this.config.dlxExchange}`);
|
|
351
|
+
}
|
|
352
|
+
throw exErr;
|
|
353
|
+
}
|
|
342
354
|
|
|
343
355
|
// Bind DLQ
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
);
|
|
349
|
-
|
|
350
|
-
if (queues.workflow) {
|
|
356
|
+
console.log(`[QueueManager] DEBUG: Binding DLQ: ${queues.dlq} to ${this.config.dlxExchange}`);
|
|
357
|
+
console.log(`[QueueManager] DEBUG: Channel state before bindQueue: closed=${channel.closed}`);
|
|
358
|
+
|
|
359
|
+
try {
|
|
351
360
|
await channel.bindQueue(
|
|
352
361
|
queues.dlq,
|
|
353
362
|
this.config.dlxExchange,
|
|
354
|
-
`${serviceName}.
|
|
363
|
+
`${serviceName}.queue.dlq`
|
|
355
364
|
);
|
|
365
|
+
console.log(`[QueueManager] DEBUG: DLQ bound, channel closed=${channel.closed}`);
|
|
366
|
+
} catch (bindErr) {
|
|
367
|
+
console.error(`[QueueManager] DEBUG: bindQueue failed:`, bindErr.message);
|
|
368
|
+
if (!channel || channel.closed) {
|
|
369
|
+
throw new Error(`Channel closed during bindQueue for ${queues.dlq}`);
|
|
370
|
+
}
|
|
371
|
+
throw bindErr;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
if (queues.workflow) {
|
|
375
|
+
console.log(`[QueueManager] DEBUG: Binding workflow DLQ: ${queues.dlq} to ${this.config.dlxExchange}`);
|
|
376
|
+
console.log(`[QueueManager] DEBUG: Channel state before workflow bindQueue: closed=${channel.closed}`);
|
|
377
|
+
|
|
378
|
+
try {
|
|
379
|
+
await channel.bindQueue(
|
|
380
|
+
queues.dlq,
|
|
381
|
+
this.config.dlxExchange,
|
|
382
|
+
`${serviceName}.workflow.dlq`
|
|
383
|
+
);
|
|
384
|
+
console.log(`[QueueManager] DEBUG: Workflow DLQ bound, channel closed=${channel.closed}`);
|
|
385
|
+
} catch (bindErr) {
|
|
386
|
+
console.error(`[QueueManager] DEBUG: workflow bindQueue failed:`, bindErr.message);
|
|
387
|
+
if (!channel || channel.closed) {
|
|
388
|
+
throw new Error(`Channel closed during workflow bindQueue`);
|
|
389
|
+
}
|
|
390
|
+
throw bindErr;
|
|
391
|
+
}
|
|
356
392
|
}
|
|
357
393
|
|
|
394
|
+
console.log(`[QueueManager] DEBUG: setupServiceQueues completed successfully, channel closed=${channel.closed}`);
|
|
358
395
|
return queues;
|
|
359
396
|
}
|
|
360
397
|
|
|
@@ -154,19 +154,29 @@ class RabbitMQClient extends EventEmitter {
|
|
|
154
154
|
try {
|
|
155
155
|
// Ensure queue exists if publishing directly to queue and using default exchange
|
|
156
156
|
if (!exchange) {
|
|
157
|
-
//
|
|
158
|
-
//
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
//
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
157
|
+
// CRITICAL: For business queues, do NOT use checkQueue() - it closes channel on 404!
|
|
158
|
+
// Business queues should already be created by setupServiceQueues() BEFORE publish is called
|
|
159
|
+
// If queue doesn't exist, that's a programming error - just proceed to publish
|
|
160
|
+
// publish() will fail with a clear error if queue doesn't exist
|
|
161
|
+
const isBusinessQueue = queueConfig.isBusinessQueue(queue);
|
|
162
|
+
|
|
163
|
+
if (isBusinessQueue) {
|
|
164
|
+
// Business queue - should already exist, skip checkQueue() to avoid channel closure
|
|
165
|
+
console.log(`[RabbitMQClient] DEBUG: Business queue ${queue}, skipping checkQueue() in publish() - queue should already exist`);
|
|
166
|
+
} else {
|
|
167
|
+
// Infrastructure queue - check if it exists
|
|
168
|
+
const queueOptions = this._getQueueOptions(queue);
|
|
169
|
+
try {
|
|
170
|
+
await this._queueChannel.checkQueue(queue);
|
|
171
|
+
// Queue exists - proceed to publish
|
|
172
|
+
} catch (checkErr) {
|
|
173
|
+
// If queue doesn't exist (404), create it
|
|
174
|
+
if (checkErr.code === 404) {
|
|
175
|
+
await this._queueChannel.assertQueue(queue, queueOptions);
|
|
176
|
+
} else {
|
|
177
|
+
// Other error (including 406) - queue exists with different args, proceed
|
|
178
|
+
console.warn(`[RabbitMQClient] Queue ${queue} exists with different arguments, using as-is`);
|
|
179
|
+
}
|
|
170
180
|
}
|
|
171
181
|
}
|
|
172
182
|
// Publish using ConfirmChannel (for publisher confirms)
|