@onlineapps/mq-client-core 1.0.5 → 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
|
@@ -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,22 @@ 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
|
-
// Use
|
|
155
|
+
// Use queueChannel (regular channel) for checkQueue/assertQueue to avoid RPC reply queue issues
|
|
126
156
|
// If queue doesn't exist (404), try to create it with default options
|
|
127
157
|
try {
|
|
128
|
-
await this.
|
|
158
|
+
await this._queueChannel.checkQueue(queue);
|
|
129
159
|
// Queue exists - proceed to publish
|
|
130
160
|
} catch (checkErr) {
|
|
131
161
|
// If queue doesn't exist (404), create it with default options
|
|
132
162
|
if (checkErr.code === 404) {
|
|
133
163
|
const queueOptions = options.queueOptions || { durable: this._config.durable };
|
|
134
|
-
await this.
|
|
164
|
+
await this._queueChannel.assertQueue(queue, queueOptions);
|
|
135
165
|
} else {
|
|
136
166
|
// Other error - rethrow
|
|
137
167
|
throw checkErr;
|
|
138
168
|
}
|
|
139
169
|
}
|
|
140
|
-
// Publish to queue
|
|
170
|
+
// Publish to queue using ConfirmChannel (for publisher confirms)
|
|
141
171
|
this._channel.sendToQueue(queue, buffer, { persistent, headers });
|
|
142
172
|
} else {
|
|
143
173
|
// If exchange is specified, assert exchange and publish to it
|
|
@@ -173,12 +203,13 @@ class RabbitMQClient extends EventEmitter {
|
|
|
173
203
|
// Skip assertQueue for reply queues (they're already created with specific settings)
|
|
174
204
|
// Reply queues start with 'rpc.reply.' and are created as non-durable
|
|
175
205
|
if (!queue.startsWith('rpc.reply.')) {
|
|
206
|
+
// Use queueChannel (regular channel) for queue operations to avoid RPC reply queue issues
|
|
176
207
|
// Simple queue assertion - infrastructure services should ensure queues exist
|
|
177
208
|
// If queue doesn't exist, assertQueue will create it with default options
|
|
178
209
|
// If it exists with different args (406), log warning and proceed
|
|
179
210
|
const queueOptions = options.queueOptions || { durable };
|
|
180
211
|
try {
|
|
181
|
-
await this.
|
|
212
|
+
await this._queueChannel.assertQueue(queue, queueOptions);
|
|
182
213
|
} catch (assertErr) {
|
|
183
214
|
// If queue exists with different arguments (406), use it as-is
|
|
184
215
|
if (assertErr.code === 406) {
|