@onlineapps/conn-infra-mq 1.1.14 → 1.1.16
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,7 +36,9 @@ class QueueManager {
|
|
|
36
36
|
if (!transport || !transport.channel) {
|
|
37
37
|
throw new Error('MQ client not connected');
|
|
38
38
|
}
|
|
39
|
-
|
|
39
|
+
// Use queueChannel for queue operations to avoid RPC reply queue issues
|
|
40
|
+
// queueChannel is a regular channel, not ConfirmChannel
|
|
41
|
+
const channel = transport.queueChannel || transport.channel;
|
|
40
42
|
|
|
41
43
|
let queueOptions;
|
|
42
44
|
|
|
@@ -186,7 +188,8 @@ class QueueManager {
|
|
|
186
188
|
if (!transport || !transport.channel) {
|
|
187
189
|
throw new Error('MQ client not connected');
|
|
188
190
|
}
|
|
189
|
-
|
|
191
|
+
// Use queueChannel for queue operations to avoid RPC reply queue issues
|
|
192
|
+
const channel = transport.queueChannel || transport.channel;
|
|
190
193
|
|
|
191
194
|
const queues = {};
|
|
192
195
|
|
|
@@ -300,7 +303,8 @@ class QueueManager {
|
|
|
300
303
|
if (!transport || !transport.channel) {
|
|
301
304
|
throw new Error('MQ client not connected');
|
|
302
305
|
}
|
|
303
|
-
|
|
306
|
+
// Use queueChannel for queue operations
|
|
307
|
+
const channel = transport.queueChannel || transport.channel;
|
|
304
308
|
|
|
305
309
|
this.managedQueues.delete(queueName);
|
|
306
310
|
return channel.deleteQueue(queueName, options);
|
|
@@ -315,7 +319,8 @@ class QueueManager {
|
|
|
315
319
|
if (!transport || !transport.channel) {
|
|
316
320
|
throw new Error('MQ client not connected');
|
|
317
321
|
}
|
|
318
|
-
|
|
322
|
+
// Use queueChannel for queue operations
|
|
323
|
+
const channel = transport.queueChannel || transport.channel;
|
|
319
324
|
|
|
320
325
|
return channel.purgeQueue(queueName);
|
|
321
326
|
}
|
|
@@ -329,7 +334,8 @@ class QueueManager {
|
|
|
329
334
|
if (!transport || !transport.channel) {
|
|
330
335
|
throw new Error('MQ client not connected');
|
|
331
336
|
}
|
|
332
|
-
|
|
337
|
+
// Use queueChannel for queue operations
|
|
338
|
+
const channel = transport.queueChannel || transport.channel;
|
|
333
339
|
|
|
334
340
|
const result = await channel.checkQueue(queueName);
|
|
335
341
|
return {
|
|
@@ -350,7 +356,8 @@ class QueueManager {
|
|
|
350
356
|
if (!transport || !transport.channel) {
|
|
351
357
|
throw new Error('MQ client not connected');
|
|
352
358
|
}
|
|
353
|
-
|
|
359
|
+
// Exchange operations can use queueChannel (regular channel) - no RPC issues
|
|
360
|
+
const channel = transport.queueChannel || transport.channel;
|
|
354
361
|
|
|
355
362
|
return channel.assertExchange(exchangeName, type, {
|
|
356
363
|
durable: options.durable !== false,
|
|
@@ -369,7 +376,8 @@ class QueueManager {
|
|
|
369
376
|
if (!transport || !transport.channel) {
|
|
370
377
|
throw new Error('MQ client not connected');
|
|
371
378
|
}
|
|
372
|
-
|
|
379
|
+
// Bind operations can use queueChannel (regular channel) - no RPC issues
|
|
380
|
+
const channel = transport.queueChannel || transport.channel;
|
|
373
381
|
|
|
374
382
|
return channel.bindQueue(queue, exchange, routingKey);
|
|
375
383
|
}
|
|
@@ -38,10 +38,19 @@ class RabbitMQClient extends EventEmitter {
|
|
|
38
38
|
|
|
39
39
|
/**
|
|
40
40
|
* Getter for channel - provides compatibility with QueueManager
|
|
41
|
+
* Returns ConfirmChannel for publish operations
|
|
41
42
|
*/
|
|
42
43
|
get channel() {
|
|
43
44
|
return this._channel;
|
|
44
45
|
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Getter for queue channel - regular channel for queue operations
|
|
49
|
+
* Use this for assertQueue, checkQueue to avoid RPC reply queue issues
|
|
50
|
+
*/
|
|
51
|
+
get queueChannel() {
|
|
52
|
+
return this._queueChannel || this._channel; // Fallback to main channel if queueChannel not available
|
|
53
|
+
}
|
|
45
54
|
|
|
46
55
|
/**
|
|
47
56
|
* Connects to RabbitMQ server and creates a confirm channel.
|
|
@@ -95,6 +104,15 @@ class RabbitMQClient extends EventEmitter {
|
|
|
95
104
|
* @returns {Promise<void>}
|
|
96
105
|
*/
|
|
97
106
|
async disconnect() {
|
|
107
|
+
try {
|
|
108
|
+
if (this._queueChannel) {
|
|
109
|
+
await this._queueChannel.close();
|
|
110
|
+
this._queueChannel = null;
|
|
111
|
+
}
|
|
112
|
+
} catch (err) {
|
|
113
|
+
// Log but don't emit - queue channel errors are less critical
|
|
114
|
+
console.warn('[RabbitMQClient] Error closing queue channel:', err.message);
|
|
115
|
+
}
|
|
98
116
|
try {
|
|
99
117
|
if (this._channel) {
|
|
100
118
|
await this._channel.close();
|
|
@@ -134,9 +152,22 @@ class RabbitMQClient extends EventEmitter {
|
|
|
134
152
|
try {
|
|
135
153
|
// Ensure queue exists if publishing directly to queue and using default exchange
|
|
136
154
|
if (!exchange) {
|
|
155
|
+
// Use queueChannel (regular channel) for queue operations to avoid RPC reply queue issues
|
|
137
156
|
// Use central config for infrastructure queues
|
|
138
157
|
const queueOptions = this._getQueueOptions(queue);
|
|
139
|
-
|
|
158
|
+
try {
|
|
159
|
+
await this._queueChannel.checkQueue(queue);
|
|
160
|
+
// Queue exists - proceed to publish
|
|
161
|
+
} catch (checkErr) {
|
|
162
|
+
// If queue doesn't exist (404), create it
|
|
163
|
+
if (checkErr.code === 404) {
|
|
164
|
+
await this._queueChannel.assertQueue(queue, queueOptions);
|
|
165
|
+
} else {
|
|
166
|
+
// Other error (including 406) - queue exists with different args, proceed
|
|
167
|
+
console.warn(`[RabbitMQClient] Queue ${queue} exists with different arguments, using as-is`);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
// Publish using ConfirmChannel (for publisher confirms)
|
|
140
171
|
this._channel.sendToQueue(queue, buffer, { persistent, headers, routingKey });
|
|
141
172
|
} else {
|
|
142
173
|
// If exchange is specified, assert exchange and publish to it
|
|
@@ -177,9 +208,10 @@ class RabbitMQClient extends EventEmitter {
|
|
|
177
208
|
|
|
178
209
|
if (isInfraQueue) {
|
|
179
210
|
// Infrastructure queue - should already exist, created by infrastructure initialization
|
|
211
|
+
// Use queueChannel (regular channel) for queue operations to avoid RPC reply queue issues
|
|
180
212
|
// Only check if it exists, don't try to create or assert with arguments
|
|
181
213
|
try {
|
|
182
|
-
await this.
|
|
214
|
+
await this._queueChannel.checkQueue(queue);
|
|
183
215
|
// Queue exists - proceed to consume
|
|
184
216
|
} catch (checkErr) {
|
|
185
217
|
if (checkErr.code === 404) {
|
|
@@ -191,13 +223,14 @@ class RabbitMQClient extends EventEmitter {
|
|
|
191
223
|
}
|
|
192
224
|
} else {
|
|
193
225
|
// Business queue - may need to be created, but use unified config
|
|
226
|
+
// Use queueChannel (regular channel) for queue operations to avoid RPC reply queue issues
|
|
194
227
|
const queueOptions = this._getQueueOptions(queue, { durable });
|
|
195
228
|
|
|
196
229
|
// Try to assert queue with our config
|
|
197
230
|
// If it fails with 406 (PRECONDITION-FAILED), queue exists with different args - use it as-is
|
|
198
231
|
// IMPORTANT: Don't try to re-assert after 406, as it will close the channel
|
|
199
232
|
try {
|
|
200
|
-
await this.
|
|
233
|
+
await this._queueChannel.assertQueue(queue, queueOptions);
|
|
201
234
|
} catch (assertErr) {
|
|
202
235
|
// If queue exists with different arguments (406), use it as-is without re-asserting
|
|
203
236
|
if (assertErr.code === 406) {
|