@onlineapps/mq-client-core 1.0.4 → 1.0.6

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/mq-client-core",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "description": "Core MQ client library for RabbitMQ - shared by infrastructure services and connectors",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -33,14 +33,24 @@ class RabbitMQClient extends EventEmitter {
33
33
 
34
34
  this._connection = null;
35
35
  this._channel = null;
36
+ this._queueChannel = null;
36
37
  }
37
38
 
38
39
  /**
39
40
  * Getter for channel - provides compatibility with QueueManager
41
+ * Returns ConfirmChannel for publish operations
40
42
  */
41
43
  get channel() {
42
44
  return this._channel;
43
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
+ }
44
54
 
45
55
  /**
46
56
  * Connects to RabbitMQ server and creates a confirm channel.
@@ -56,13 +66,24 @@ class RabbitMQClient extends EventEmitter {
56
66
  this.emit('error', new Error('RabbitMQ connection closed unexpectedly'));
57
67
  });
58
68
 
59
- // Use ConfirmChannel to enable publisher confirms
69
+ // Use ConfirmChannel to enable publisher confirms for publish operations
60
70
  this._channel = await this._connection.createConfirmChannel();
61
71
  this._channel.on('error', (err) => this.emit('error', err));
62
72
  this._channel.on('close', () => {
63
73
  // Emit a channel close error
64
74
  this.emit('error', new Error('RabbitMQ channel closed unexpectedly'));
65
75
  });
76
+
77
+ // Create a separate regular channel for queue operations (assertQueue, checkQueue)
78
+ // This avoids RPC reply queue issues with ConfirmChannel.assertQueue()
79
+ this._queueChannel = await this._connection.createChannel();
80
+ this._queueChannel.on('error', (err) => {
81
+ // Log but don't emit - queue channel errors are less critical
82
+ console.warn('[RabbitMQClient] Queue channel error:', err.message);
83
+ });
84
+ this._queueChannel.on('close', () => {
85
+ console.warn('[RabbitMQClient] Queue channel closed');
86
+ });
66
87
  } catch (err) {
67
88
  // Cleanup partially created resources
68
89
  if (this._connection) {
@@ -82,6 +103,15 @@ class RabbitMQClient extends EventEmitter {
82
103
  * @returns {Promise<void>}
83
104
  */
84
105
  async disconnect() {
106
+ try {
107
+ if (this._queueChannel) {
108
+ await this._queueChannel.close();
109
+ this._queueChannel = null;
110
+ }
111
+ } catch (err) {
112
+ // Log but don't emit - queue channel errors are less critical
113
+ console.warn('[RabbitMQClient] Error closing queue channel:', err.message);
114
+ }
85
115
  try {
86
116
  if (this._channel) {
87
117
  await this._channel.close();
@@ -122,22 +152,23 @@ class RabbitMQClient extends EventEmitter {
122
152
  // Ensure queue exists if publishing directly to queue and using default exchange
123
153
  if (!exchange) {
124
154
  // For infrastructure queues, they should already exist with specific arguments
125
- // Try to check if queue exists first, if not, create with default options
126
- // If it exists with different args (406), use it as-is
127
- const queueOptions = options.queueOptions || { durable: this._config.durable };
155
+ // Use queueChannel (regular channel) for checkQueue/assertQueue to avoid RPC reply queue issues
156
+ // If queue doesn't exist (404), try to create it with default options
128
157
  try {
129
- await this._channel.assertQueue(queue, queueOptions);
130
- } catch (assertErr) {
131
- // If queue exists with different arguments (406), use it as-is
132
- if (assertErr.code === 406) {
133
- console.warn(`[RabbitMQClient] Queue ${queue} exists with different arguments, using as-is:`, assertErr.message);
134
- // Don't try to re-assert - just proceed to publish
158
+ await this._queueChannel.checkQueue(queue);
159
+ // Queue exists - proceed to publish
160
+ } catch (checkErr) {
161
+ // If queue doesn't exist (404), create it with default options
162
+ if (checkErr.code === 404) {
163
+ const queueOptions = options.queueOptions || { durable: this._config.durable };
164
+ await this._queueChannel.assertQueue(queue, queueOptions);
135
165
  } else {
136
166
  // Other error - rethrow
137
- throw assertErr;
167
+ throw checkErr;
138
168
  }
139
169
  }
140
- this._channel.sendToQueue(queue, buffer, { persistent, headers, routingKey });
170
+ // Publish to queue using ConfirmChannel (for publisher confirms)
171
+ this._channel.sendToQueue(queue, buffer, { persistent, headers });
141
172
  } else {
142
173
  // If exchange is specified, assert exchange and publish to it
143
174
  await this._channel.assertExchange(exchange, 'direct', { durable: this._config.durable });
@@ -172,12 +203,13 @@ class RabbitMQClient extends EventEmitter {
172
203
  // Skip assertQueue for reply queues (they're already created with specific settings)
173
204
  // Reply queues start with 'rpc.reply.' and are created as non-durable
174
205
  if (!queue.startsWith('rpc.reply.')) {
206
+ // Use queueChannel (regular channel) for queue operations to avoid RPC reply queue issues
175
207
  // Simple queue assertion - infrastructure services should ensure queues exist
176
208
  // If queue doesn't exist, assertQueue will create it with default options
177
209
  // If it exists with different args (406), log warning and proceed
178
210
  const queueOptions = options.queueOptions || { durable };
179
211
  try {
180
- await this._channel.assertQueue(queue, queueOptions);
212
+ await this._queueChannel.assertQueue(queue, queueOptions);
181
213
  } catch (assertErr) {
182
214
  // If queue exists with different arguments (406), use it as-is
183
215
  if (assertErr.code === 406) {