@onlineapps/conn-infra-mq 1.1.10 → 1.1.11
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 +47 -17
package/package.json
CHANGED
|
@@ -154,30 +154,60 @@ class QueueManager {
|
|
|
154
154
|
const queues = {};
|
|
155
155
|
|
|
156
156
|
// Create main processing queue
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
157
|
+
// Handle PRECONDITION-FAILED gracefully - queue may exist with different args
|
|
158
|
+
try {
|
|
159
|
+
await this.ensureQueue(`${serviceName}.queue`, {
|
|
160
|
+
ttl: options.ttl || this.config.defaultTTL,
|
|
161
|
+
dlq: true,
|
|
162
|
+
durable: true,
|
|
163
|
+
maxRetries: this.config.maxRetries
|
|
164
|
+
});
|
|
165
|
+
} catch (error) {
|
|
166
|
+
if (error.code === 406) {
|
|
167
|
+
// Queue exists with different arguments - use it as-is
|
|
168
|
+
console.warn(`[QueueManager] Queue ${serviceName}.queue exists with different arguments, using as-is`);
|
|
169
|
+
// Verify queue exists
|
|
170
|
+
await channel.checkQueue(`${serviceName}.queue`);
|
|
171
|
+
} else {
|
|
172
|
+
throw error;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
163
175
|
queues.main = `${serviceName}.queue`;
|
|
164
176
|
|
|
165
177
|
// Create dead letter queue
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
178
|
+
try {
|
|
179
|
+
await this.ensureQueue(`${serviceName}.dlq`, {
|
|
180
|
+
ttl: null, // No TTL for DLQ
|
|
181
|
+
dlq: false,
|
|
182
|
+
durable: true,
|
|
183
|
+
autoDelete: false
|
|
184
|
+
});
|
|
185
|
+
} catch (error) {
|
|
186
|
+
if (error.code === 406) {
|
|
187
|
+
console.warn(`[QueueManager] Queue ${serviceName}.dlq exists with different arguments, using as-is`);
|
|
188
|
+
await channel.checkQueue(`${serviceName}.dlq`);
|
|
189
|
+
} else {
|
|
190
|
+
throw error;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
172
193
|
queues.dlq = `${serviceName}.dlq`;
|
|
173
194
|
|
|
174
195
|
// Create workflow queue if requested
|
|
175
196
|
if (options.includeWorkflow !== false) {
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
197
|
+
try {
|
|
198
|
+
await this.ensureQueue(`${serviceName}.workflow`, {
|
|
199
|
+
ttl: options.workflowTTL || this.config.defaultTTL,
|
|
200
|
+
dlq: true,
|
|
201
|
+
durable: true
|
|
202
|
+
});
|
|
203
|
+
} catch (error) {
|
|
204
|
+
if (error.code === 406) {
|
|
205
|
+
console.warn(`[QueueManager] Queue ${serviceName}.workflow exists with different arguments, using as-is`);
|
|
206
|
+
await channel.checkQueue(`${serviceName}.workflow`);
|
|
207
|
+
} else {
|
|
208
|
+
throw error;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
181
211
|
queues.workflow = `${serviceName}.workflow`;
|
|
182
212
|
}
|
|
183
213
|
|