@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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onlineapps/conn-infra-mq",
3
- "version": "1.1.10",
3
+ "version": "1.1.11",
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": {
@@ -154,30 +154,60 @@ class QueueManager {
154
154
  const queues = {};
155
155
 
156
156
  // Create main processing queue
157
- await this.ensureQueue(`${serviceName}.queue`, {
158
- ttl: options.ttl || this.config.defaultTTL,
159
- dlq: true,
160
- durable: true,
161
- maxRetries: this.config.maxRetries
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
- await this.ensureQueue(`${serviceName}.dlq`, {
167
- ttl: null, // No TTL for DLQ
168
- dlq: false,
169
- durable: true,
170
- autoDelete: false
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
- await this.ensureQueue(`${serviceName}.workflow`, {
177
- ttl: options.workflowTTL || this.config.defaultTTL,
178
- dlq: true,
179
- durable: true
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