@onlineapps/conn-infra-mq 1.1.20 → 1.1.21
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 +33 -10
- package/src/transports/rabbitmqClient.js +14 -13
package/package.json
CHANGED
|
@@ -103,17 +103,40 @@ class QueueManager {
|
|
|
103
103
|
throw new Error('Channel closed during checkQueue - cannot verify queue');
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
-
// If queue doesn't exist (404),
|
|
107
|
-
//
|
|
106
|
+
// If queue doesn't exist (404), create it using assertQueue with proper error handling
|
|
107
|
+
// Business queues MUST be created with specific arguments (TTL, DLQ, max-length) from queueConfig
|
|
108
|
+
// Lazy creation via sendToQueue() is NOT suitable - it creates queue with default arguments
|
|
108
109
|
if (checkErr.code === 404) {
|
|
109
|
-
//
|
|
110
|
-
//
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
110
|
+
// CRITICAL: Business queues MUST be created explicitly with correct arguments
|
|
111
|
+
// Use assertQueue() on regular channel (queueChannel) - this should work without RPC issues
|
|
112
|
+
// If it fails, it's a real problem that needs to be fixed, not worked around
|
|
113
|
+
try {
|
|
114
|
+
if (!channel || channel.closed) {
|
|
115
|
+
throw new Error('Channel closed - cannot create queue');
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// For business queues: use assertQueue with queueOptions from queueConfig
|
|
119
|
+
// This ensures correct TTL, DLQ, max-length arguments
|
|
120
|
+
return await channel.assertQueue(queueName, queueOptions);
|
|
121
|
+
} catch (assertErr) {
|
|
122
|
+
// If channel closed during assertQueue, it's a real error
|
|
123
|
+
if (!channel || channel.closed) {
|
|
124
|
+
throw new Error(`Channel closed during assertQueue for ${queueName} - check channel management`);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// If 406 PRECONDITION-FAILED, queue exists with different args
|
|
128
|
+
if (assertErr.code === 406) {
|
|
129
|
+
console.warn(`[QueueManager] Queue ${queueName} exists with different arguments:`, assertErr.message);
|
|
130
|
+
// Try to get queue info anyway
|
|
131
|
+
if (!channel || channel.closed) {
|
|
132
|
+
throw new Error('Channel closed - cannot check existing queue');
|
|
133
|
+
}
|
|
134
|
+
return await channel.checkQueue(queueName);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// Other errors - rethrow
|
|
138
|
+
throw assertErr;
|
|
139
|
+
}
|
|
117
140
|
} else {
|
|
118
141
|
// Other error (including 406) - queue exists with different args
|
|
119
142
|
// Log warning and return queue info without asserting
|
|
@@ -222,23 +222,24 @@ class RabbitMQClient extends EventEmitter {
|
|
|
222
222
|
throw checkErr;
|
|
223
223
|
}
|
|
224
224
|
} else {
|
|
225
|
-
// Business queue -
|
|
225
|
+
// Business queue - should already be created by setupServiceQueues() BEFORE consume is called
|
|
226
226
|
// Use queueChannel (regular channel) for queue operations to avoid RPC reply queue issues
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
// Try to assert queue with our config
|
|
230
|
-
// If it fails with 406 (PRECONDITION-FAILED), queue exists with different args - use it as-is
|
|
231
|
-
// IMPORTANT: Don't try to re-assert after 406, as it will close the channel
|
|
227
|
+
// Only check if it exists - don't try to create it here (that's setupServiceQueues() responsibility)
|
|
232
228
|
try {
|
|
233
|
-
await this._queueChannel.
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
if (
|
|
237
|
-
|
|
238
|
-
|
|
229
|
+
await this._queueChannel.checkQueue(queue);
|
|
230
|
+
// Queue exists - proceed to consume
|
|
231
|
+
} catch (checkErr) {
|
|
232
|
+
if (checkErr.code === 404) {
|
|
233
|
+
// Queue doesn't exist - this is an error, queue should have been created by setupServiceQueues()
|
|
234
|
+
throw new Error(`Business queue '${queue}' not found. Queue should be created by setupServiceQueues() before consuming.`);
|
|
235
|
+
}
|
|
236
|
+
// Other error (including 406) - queue exists with different args, use it as-is
|
|
237
|
+
if (checkErr.code === 406) {
|
|
238
|
+
console.warn(`[RabbitMQClient] Queue ${queue} exists with different arguments, using as-is:`, checkErr.message);
|
|
239
|
+
// Proceed to consume - queue exists, just with different args
|
|
239
240
|
} else {
|
|
240
241
|
// Other error - rethrow
|
|
241
|
-
throw
|
|
242
|
+
throw checkErr;
|
|
242
243
|
}
|
|
243
244
|
}
|
|
244
245
|
}
|