@onlineapps/conn-infra-mq 1.1.15 → 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
|
@@ -188,7 +188,8 @@ class QueueManager {
|
|
|
188
188
|
if (!transport || !transport.channel) {
|
|
189
189
|
throw new Error('MQ client not connected');
|
|
190
190
|
}
|
|
191
|
-
|
|
191
|
+
// Use queueChannel for queue operations to avoid RPC reply queue issues
|
|
192
|
+
const channel = transport.queueChannel || transport.channel;
|
|
192
193
|
|
|
193
194
|
const queues = {};
|
|
194
195
|
|
|
@@ -302,7 +303,8 @@ class QueueManager {
|
|
|
302
303
|
if (!transport || !transport.channel) {
|
|
303
304
|
throw new Error('MQ client not connected');
|
|
304
305
|
}
|
|
305
|
-
|
|
306
|
+
// Use queueChannel for queue operations
|
|
307
|
+
const channel = transport.queueChannel || transport.channel;
|
|
306
308
|
|
|
307
309
|
this.managedQueues.delete(queueName);
|
|
308
310
|
return channel.deleteQueue(queueName, options);
|
|
@@ -354,7 +356,8 @@ class QueueManager {
|
|
|
354
356
|
if (!transport || !transport.channel) {
|
|
355
357
|
throw new Error('MQ client not connected');
|
|
356
358
|
}
|
|
357
|
-
|
|
359
|
+
// Exchange operations can use queueChannel (regular channel) - no RPC issues
|
|
360
|
+
const channel = transport.queueChannel || transport.channel;
|
|
358
361
|
|
|
359
362
|
return channel.assertExchange(exchangeName, type, {
|
|
360
363
|
durable: options.durable !== false,
|
|
@@ -373,7 +376,8 @@ class QueueManager {
|
|
|
373
376
|
if (!transport || !transport.channel) {
|
|
374
377
|
throw new Error('MQ client not connected');
|
|
375
378
|
}
|
|
376
|
-
|
|
379
|
+
// Bind operations can use queueChannel (regular channel) - no RPC issues
|
|
380
|
+
const channel = transport.queueChannel || transport.channel;
|
|
377
381
|
|
|
378
382
|
return channel.bindQueue(queue, exchange, routingKey);
|
|
379
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) {
|