@autofleet/rabbit 2.1.5 → 2.1.7
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 +1 -0
- package/dist/index.js +13 -0
- package/dist/logger.d.ts +2 -0
- package/dist/logger.js +5 -0
- package/package.json +2 -1
- package/src/index.ts +12 -0
- package/src/logger.ts +5 -0
package/dist/index.d.ts
CHANGED
|
@@ -57,5 +57,6 @@ declare class RabbitMq implements IAfRabbitMq {
|
|
|
57
57
|
consumeFromExchange(queue: string, exchange: string, callback: (msg: any, ack: Function, nack: Function) => any, options?: any): Promise<void>;
|
|
58
58
|
publish(exchange: string, content: any, customHeaders?: any): Promise<unknown>;
|
|
59
59
|
sendToQueue(queue: string, content: any, options?: any, customHeaders?: any): Promise<void>;
|
|
60
|
+
isConnected(): Promise<boolean>;
|
|
60
61
|
}
|
|
61
62
|
export default RabbitMq;
|
package/dist/index.js
CHANGED
|
@@ -38,6 +38,7 @@ const moment_1 = __importDefault(require("moment"));
|
|
|
38
38
|
const amqp_connection_manager_1 = require("amqp-connection-manager");
|
|
39
39
|
const events_1 = require("events");
|
|
40
40
|
const outbreak_1 = require("@autofleet/outbreak");
|
|
41
|
+
const logger_1 = __importDefault(require("./logger"));
|
|
41
42
|
const rabbitError_1 = __importDefault(require("./rabbitError"));
|
|
42
43
|
const redis_1 = __importDefault(require("./redis"));
|
|
43
44
|
const DEFAULT_DEAD_TTL_TWO_DAYS = 60000 * 60 * 48;
|
|
@@ -59,6 +60,9 @@ class RabbitMq {
|
|
|
59
60
|
const { properties: { timestamp, headers } } = msg;
|
|
60
61
|
if (timestamp && (headers === null || headers === void 0 ? void 0 : headers.redisTimestampValidationKey) && this.redisClient) {
|
|
61
62
|
const lastMessageTimestamp = yield this.redisClient.getAsync(headers.redisTimestampValidationKey);
|
|
63
|
+
logger_1.default.info('rabbit: checking if should consume params', {
|
|
64
|
+
msg, timestamp, headers, lastMessageTimestamp,
|
|
65
|
+
});
|
|
62
66
|
return !lastMessageTimestamp || moment_1.default(parseInt(lastMessageTimestamp, 10) * SECONDS_TO_MILLISECONDS).isBefore(moment_1.default(timestamp * SECONDS_TO_MILLISECONDS));
|
|
63
67
|
}
|
|
64
68
|
return true;
|
|
@@ -221,6 +225,7 @@ class RabbitMq {
|
|
|
221
225
|
const parsedMessage = RabbitMq.parseMsg(msg);
|
|
222
226
|
outbreak_1.newTrace(outbreak_1.traceTypes.RABBIT);
|
|
223
227
|
const shouldConsume = yield this.shouldConsumeMessageByTimestamp(parsedMessage);
|
|
228
|
+
logger_1.default.info('rabbit: trying to consume', { queue, shouldConsume, msg });
|
|
224
229
|
if (!shouldConsume) {
|
|
225
230
|
return this.ack(channel)(msg);
|
|
226
231
|
}
|
|
@@ -248,6 +253,7 @@ class RabbitMq {
|
|
|
248
253
|
const parsedMessage = RabbitMq.parseMsg(msg);
|
|
249
254
|
outbreak_1.newTrace(outbreak_1.traceTypes.RABBIT);
|
|
250
255
|
const shouldConsume = yield this.shouldConsumeMessageByTimestamp(parsedMessage);
|
|
256
|
+
logger_1.default.info('rabbit: trying to consume', { queue, shouldConsume, msg });
|
|
251
257
|
if (!shouldConsume) {
|
|
252
258
|
return this.ack(channel)(msg);
|
|
253
259
|
}
|
|
@@ -278,8 +284,15 @@ class RabbitMq {
|
|
|
278
284
|
RabbitMq.validateName('queue', queue);
|
|
279
285
|
const channel = yield this.assertChannel();
|
|
280
286
|
yield this.assertQueue(queue, options);
|
|
287
|
+
logger_1.default.info('rabbit: sending to queue', { queue, content, customHeaders });
|
|
281
288
|
return channel.sendToQueue(queue, Buffer.from(JSON.stringify(content)), RabbitMq.getPublishOptions(customHeaders));
|
|
282
289
|
});
|
|
283
290
|
}
|
|
291
|
+
isConnected() {
|
|
292
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
293
|
+
const connection = yield this.getConnection();
|
|
294
|
+
return connection.isConnected();
|
|
295
|
+
});
|
|
296
|
+
}
|
|
284
297
|
}
|
|
285
298
|
exports.default = RabbitMq;
|
package/dist/logger.d.ts
ADDED
package/dist/logger.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@autofleet/rabbit",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.7",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
"dev": "nodemon"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
+
"@autofleet/logger": "^1.2.8",
|
|
18
19
|
"@types/amqp-connection-manager": "^2.0.10",
|
|
19
20
|
"@types/amqplib": "^0.5.16",
|
|
20
21
|
"@types/uuid": "^8.3.3",
|
package/src/index.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { ConfirmChannel, Options } from 'amqplib';
|
|
|
6
6
|
import { AmqpConnectionManager, ChannelWrapper, connect } from 'amqp-connection-manager';
|
|
7
7
|
import { EventEmitter } from 'events';
|
|
8
8
|
import { newTrace, traceTypes } from '@autofleet/outbreak';
|
|
9
|
+
import logger from './logger';
|
|
9
10
|
import RabbitError from './rabbitError';
|
|
10
11
|
import getRedisInstance, { RedisConfig } from './redis';
|
|
11
12
|
|
|
@@ -110,6 +111,9 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
110
111
|
const { properties: { timestamp, headers } } = msg;
|
|
111
112
|
if (timestamp && headers?.redisTimestampValidationKey && this.redisClient) {
|
|
112
113
|
const lastMessageTimestamp = await this.redisClient.getAsync(headers.redisTimestampValidationKey);
|
|
114
|
+
logger.info('rabbit: checking if should consume params', {
|
|
115
|
+
msg, timestamp, headers, lastMessageTimestamp,
|
|
116
|
+
});
|
|
113
117
|
return !lastMessageTimestamp || moment(parseInt(lastMessageTimestamp, 10) * SECONDS_TO_MILLISECONDS).isBefore(moment(timestamp * SECONDS_TO_MILLISECONDS));
|
|
114
118
|
}
|
|
115
119
|
return true;
|
|
@@ -252,6 +256,7 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
252
256
|
const parsedMessage = RabbitMq.parseMsg(msg);
|
|
253
257
|
newTrace(traceTypes.RABBIT);
|
|
254
258
|
const shouldConsume = await this.shouldConsumeMessageByTimestamp(parsedMessage);
|
|
259
|
+
logger.info('rabbit: trying to consume', { queue, shouldConsume, msg });
|
|
255
260
|
if (!shouldConsume) {
|
|
256
261
|
return this.ack(channel)(msg);
|
|
257
262
|
}
|
|
@@ -282,6 +287,7 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
282
287
|
const parsedMessage = RabbitMq.parseMsg(msg);
|
|
283
288
|
newTrace(traceTypes.RABBIT);
|
|
284
289
|
const shouldConsume = await this.shouldConsumeMessageByTimestamp(parsedMessage);
|
|
290
|
+
logger.info('rabbit: trying to consume', { queue, shouldConsume, msg });
|
|
285
291
|
if (!shouldConsume) {
|
|
286
292
|
return this.ack(channel)(msg);
|
|
287
293
|
}
|
|
@@ -312,10 +318,16 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
312
318
|
RabbitMq.validateName('queue', queue);
|
|
313
319
|
const channel: ChannelWrapper = await this.assertChannel();
|
|
314
320
|
await this.assertQueue(queue, options);
|
|
321
|
+
logger.info('rabbit: sending to queue', { queue, content, customHeaders });
|
|
315
322
|
return channel.sendToQueue(queue,
|
|
316
323
|
Buffer.from(JSON.stringify(content)),
|
|
317
324
|
RabbitMq.getPublishOptions(customHeaders));
|
|
318
325
|
}
|
|
326
|
+
|
|
327
|
+
async isConnected() : Promise<boolean> {
|
|
328
|
+
const connection = await this.getConnection();
|
|
329
|
+
return connection.isConnected();
|
|
330
|
+
}
|
|
319
331
|
}
|
|
320
332
|
|
|
321
333
|
export default RabbitMq;
|