@autofleet/rabbit 3.2.0 → 3.2.2
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/dist/index.d.ts +0 -3
- package/dist/index.js +11 -5
- package/package.json +1 -1
- package/src/index.ts +17 -14
package/dist/index.d.ts
CHANGED
|
@@ -64,9 +64,6 @@ declare class RabbitMq implements IAfRabbitMq {
|
|
|
64
64
|
options: AfRabbitOptions | undefined;
|
|
65
65
|
redisClient: any;
|
|
66
66
|
redisLock?: RedisLockType;
|
|
67
|
-
userName: string;
|
|
68
|
-
password: string;
|
|
69
|
-
host: string;
|
|
70
67
|
/** Array of consumers tags used for canceling consumption */
|
|
71
68
|
consumersTags: Array<[ConfirmChannel, string]>;
|
|
72
69
|
private consumers;
|
package/dist/index.js
CHANGED
|
@@ -80,9 +80,6 @@ class RabbitMq {
|
|
|
80
80
|
});
|
|
81
81
|
}
|
|
82
82
|
};
|
|
83
|
-
this.userName = process.env.RABBITMQ_USERNAME || 'guest';
|
|
84
|
-
this.password = process.env.RABBITMQ_PASSWORD || 'guest';
|
|
85
|
-
this.host = options?.rabbitHost || process.env.RABBITMQ_SERVICE_HOST || 'localhost';
|
|
86
83
|
this.em = new events_1.EventEmitter();
|
|
87
84
|
this.channel = null;
|
|
88
85
|
this.connection = null;
|
|
@@ -163,8 +160,17 @@ class RabbitMq {
|
|
|
163
160
|
}
|
|
164
161
|
this.creatingConnection = true;
|
|
165
162
|
let isResolved = false;
|
|
166
|
-
|
|
167
|
-
|
|
163
|
+
const findServers = () => {
|
|
164
|
+
const userName = process.env.RABBITMQ_USERNAME || 'guest';
|
|
165
|
+
const password = process.env.RABBITMQ_PASSWORD || 'guest';
|
|
166
|
+
const host = this.options?.rabbitHost || process.env.RABBITMQ_SERVICE_HOST || 'localhost';
|
|
167
|
+
debug('rabbit: creating connection', { host, userName, HEARTBEAT });
|
|
168
|
+
return [`amqp://${userName}:${password}@${host}?heartbeat=${HEARTBEAT}`];
|
|
169
|
+
};
|
|
170
|
+
const defaultUrls = findServers();
|
|
171
|
+
const connection = await amqp_connection_manager_1.connect(defaultUrls, {
|
|
172
|
+
findServers,
|
|
173
|
+
});
|
|
168
174
|
this.connection = connection;
|
|
169
175
|
this.connection.on('error', (err) => {
|
|
170
176
|
logger_1.default.error('rabbit: connection error', { err });
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -39,6 +39,7 @@ import {
|
|
|
39
39
|
const debug = logger.info;
|
|
40
40
|
|
|
41
41
|
const PUBLISH_TIMEOUT = 1000 * 10;
|
|
42
|
+
|
|
42
43
|
export interface IAfRabbitMq {
|
|
43
44
|
ack: any;
|
|
44
45
|
nack: any;
|
|
@@ -150,24 +151,12 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
150
151
|
|
|
151
152
|
redisLock?: RedisLockType;
|
|
152
153
|
|
|
153
|
-
userName: string;
|
|
154
|
-
|
|
155
|
-
password: string;
|
|
156
|
-
|
|
157
|
-
host: string;
|
|
158
|
-
|
|
159
154
|
/** Array of consumers tags used for canceling consumption */
|
|
160
155
|
consumersTags: Array<[ConfirmChannel, string]>;
|
|
161
156
|
|
|
162
157
|
private consumers: Array<AfConsumer> = [];
|
|
163
158
|
|
|
164
159
|
constructor(options?: AfRabbitOptions, redisConfig?: RedisConfig) {
|
|
165
|
-
this.userName = process.env.RABBITMQ_USERNAME || 'guest';
|
|
166
|
-
|
|
167
|
-
this.password = process.env.RABBITMQ_PASSWORD || 'guest';
|
|
168
|
-
|
|
169
|
-
this.host = options?.rabbitHost || process.env.RABBITMQ_SERVICE_HOST || 'localhost';
|
|
170
|
-
|
|
171
160
|
this.em = new EventEmitter();
|
|
172
161
|
this.channel = null;
|
|
173
162
|
this.connection = null;
|
|
@@ -290,8 +279,22 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
290
279
|
}
|
|
291
280
|
this.creatingConnection = true;
|
|
292
281
|
let isResolved = false;
|
|
293
|
-
|
|
294
|
-
const
|
|
282
|
+
|
|
283
|
+
const findServers = () => {
|
|
284
|
+
const userName = process.env.RABBITMQ_USERNAME || 'guest';
|
|
285
|
+
const password = process.env.RABBITMQ_PASSWORD || 'guest';
|
|
286
|
+
const host = this.options?.rabbitHost || process.env.RABBITMQ_SERVICE_HOST || 'localhost';
|
|
287
|
+
|
|
288
|
+
debug('rabbit: creating connection', { host, userName, HEARTBEAT });
|
|
289
|
+
|
|
290
|
+
return [`amqp://${userName}:${password}@${host}?heartbeat=${HEARTBEAT}`];
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
const defaultUrls = findServers();
|
|
294
|
+
const connection: AmqpConnectionManager = await connect(defaultUrls, {
|
|
295
|
+
findServers,
|
|
296
|
+
});
|
|
297
|
+
|
|
295
298
|
this.connection = connection;
|
|
296
299
|
this.connection.on('error', (err) => {
|
|
297
300
|
logger.error('rabbit: connection error', { err });
|