@onlineapps/mq-client-core 1.0.18 → 1.0.20
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 +1 -1
- package/src/index.js +12 -20
- package/src/transports/rabbitmqClient.js +6 -1
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -18,27 +18,19 @@ const {
|
|
|
18
18
|
} = require('./utils/errorHandler');
|
|
19
19
|
const { initInfrastructureQueues } = require('./utils/initInfrastructureQueues');
|
|
20
20
|
|
|
21
|
-
// Export BaseClient as default, with additional exports
|
|
21
|
+
// Export BaseClient as default (constructor), with additional named exports
|
|
22
22
|
// NOTE: When destructuring, use: const { initInfrastructureQueues } = require('@onlineapps/mq-client-core');
|
|
23
23
|
// When using default, use: const BaseClient = require('@onlineapps/mq-client-core');
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
24
|
+
// BaseClient must be a constructor, so we export it directly and attach other exports as properties
|
|
25
|
+
module.exports = BaseClient;
|
|
26
|
+
module.exports.BaseClient = BaseClient;
|
|
27
|
+
module.exports.RabbitMQClient = RabbitMQClient;
|
|
28
|
+
module.exports.initInfrastructureQueues = initInfrastructureQueues;
|
|
29
|
+
module.exports.errors = {
|
|
30
|
+
ValidationError,
|
|
31
|
+
ConnectionError,
|
|
32
|
+
PublishError,
|
|
33
|
+
ConsumeError,
|
|
34
|
+
SerializationError,
|
|
35
35
|
};
|
|
36
36
|
|
|
37
|
-
// Set BaseClient as default export (for backward compatibility)
|
|
38
|
-
// Also attach all properties to the exported object
|
|
39
|
-
Object.setPrototypeOf(mqExports, BaseClient);
|
|
40
|
-
Object.assign(mqExports, BaseClient);
|
|
41
|
-
|
|
42
|
-
// Export as both default and named exports
|
|
43
|
-
module.exports = mqExports;
|
|
44
|
-
|
|
@@ -59,7 +59,12 @@ class RabbitMQClient extends EventEmitter {
|
|
|
59
59
|
*/
|
|
60
60
|
async connect() {
|
|
61
61
|
try {
|
|
62
|
-
|
|
62
|
+
// Add connection timeout to prevent hanging
|
|
63
|
+
const connectPromise = amqp.connect(this._config.host);
|
|
64
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
65
|
+
setTimeout(() => reject(new Error('Connection timeout after 10 seconds')), 10000);
|
|
66
|
+
});
|
|
67
|
+
this._connection = await Promise.race([connectPromise, timeoutPromise]);
|
|
63
68
|
this._connection.on('error', (err) => this.emit('error', err));
|
|
64
69
|
this._connection.on('close', () => {
|
|
65
70
|
// Emit a connection close error to notify listeners
|