@autofleet/rabbit 2.2.6 → 2.2.8-add-context-1
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.js +2 -5
- package/package.json +1 -1
- package/src/index.ts +2 -5
package/dist/index.js
CHANGED
|
@@ -18,6 +18,7 @@ const moment_1 = __importDefault(require("moment"));
|
|
|
18
18
|
const redis_lock_1 = __importDefault(require("redis-lock"));
|
|
19
19
|
const amqp_connection_manager_1 = require("amqp-connection-manager");
|
|
20
20
|
const events_1 = require("events");
|
|
21
|
+
const outbreak_1 = require("@autofleet/outbreak");
|
|
21
22
|
// import { newTrace, traceTypes } from '@autofleet/outbreak';
|
|
22
23
|
const util_1 = require("util");
|
|
23
24
|
const logger_1 = __importDefault(require("./logger"));
|
|
@@ -55,9 +56,6 @@ class RabbitMq {
|
|
|
55
56
|
const { properties: { timestamp, headers } } = msg;
|
|
56
57
|
if (timestamp && (headers === null || headers === void 0 ? void 0 : headers.redisTimestampValidationKey) && this.redisClient) {
|
|
57
58
|
const lastMessageTimestamp = yield this.redisClient.getAsync(headers.redisTimestampValidationKey);
|
|
58
|
-
logger_1.default.info('rabbit: checking if should consume params', {
|
|
59
|
-
msg, timestamp, headers, lastMessageTimestamp,
|
|
60
|
-
});
|
|
61
59
|
return !lastMessageTimestamp || (parseInt(lastMessageTimestamp, 10) <= parseInt(timestamp, 10));
|
|
62
60
|
}
|
|
63
61
|
return true;
|
|
@@ -282,11 +280,11 @@ class RabbitMq {
|
|
|
282
280
|
}
|
|
283
281
|
const parsedMessage = RabbitMq.parseMsg(msg);
|
|
284
282
|
const shouldConsume = yield this.shouldConsumeMessageByTimestamp(parsedMessage);
|
|
285
|
-
logger_1.default.info('rabbit: trying to consume', { queue, shouldConsume, msg });
|
|
286
283
|
if (!shouldConsume) {
|
|
287
284
|
return this.ack(channel, msg)(msg);
|
|
288
285
|
}
|
|
289
286
|
try {
|
|
287
|
+
outbreak_1.newTrace(outbreak_1.traceTypes.RABBIT);
|
|
290
288
|
yield callback(parsedMessage, this.ack(channel, msg, true), this.nack(channel, queue, optionsWithDefaults, { messageTtl: deadMessageTtl }, msg));
|
|
291
289
|
}
|
|
292
290
|
catch (e) {
|
|
@@ -332,7 +330,6 @@ class RabbitMq {
|
|
|
332
330
|
RabbitMq.validateName('queue', queue);
|
|
333
331
|
const channel = yield this.assertChannel();
|
|
334
332
|
yield this.assertQueue(queue, options);
|
|
335
|
-
logger_1.default.info('rabbit: sending to queue', { queue, content, customHeaders });
|
|
336
333
|
return channel.sendToQueue(queue, Buffer.from(JSON.stringify(content)), RabbitMq.getPublishOptions(customHeaders));
|
|
337
334
|
}));
|
|
338
335
|
});
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -5,6 +5,7 @@ import RedisLock from 'redis-lock';
|
|
|
5
5
|
import { ConfirmChannel, Options, ConsumeMessage } from 'amqplib';
|
|
6
6
|
import { AmqpConnectionManager, ChannelWrapper, connect } from 'amqp-connection-manager';
|
|
7
7
|
import { EventEmitter } from 'events';
|
|
8
|
+
import { newTrace, traceTypes } from '@autofleet/outbreak';
|
|
8
9
|
// import { newTrace, traceTypes } from '@autofleet/outbreak';
|
|
9
10
|
import { promisify } from 'util';
|
|
10
11
|
import logger from './logger';
|
|
@@ -150,9 +151,6 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
150
151
|
const { properties: { timestamp, headers } } = msg;
|
|
151
152
|
if (timestamp && headers?.redisTimestampValidationKey && this.redisClient) {
|
|
152
153
|
const lastMessageTimestamp = await this.redisClient.getAsync(headers.redisTimestampValidationKey);
|
|
153
|
-
logger.info('rabbit: checking if should consume params', {
|
|
154
|
-
msg, timestamp, headers, lastMessageTimestamp,
|
|
155
|
-
});
|
|
156
154
|
return !lastMessageTimestamp || (parseInt(lastMessageTimestamp, 10) <= parseInt(timestamp, 10));
|
|
157
155
|
}
|
|
158
156
|
return true;
|
|
@@ -355,11 +353,11 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
355
353
|
}
|
|
356
354
|
const parsedMessage = RabbitMq.parseMsg(msg);
|
|
357
355
|
const shouldConsume = await this.shouldConsumeMessageByTimestamp(parsedMessage);
|
|
358
|
-
logger.info('rabbit: trying to consume', { queue, shouldConsume, msg });
|
|
359
356
|
if (!shouldConsume) {
|
|
360
357
|
return this.ack(channel, msg)(msg);
|
|
361
358
|
}
|
|
362
359
|
try {
|
|
360
|
+
newTrace(traceTypes.RABBIT);
|
|
363
361
|
await callback(
|
|
364
362
|
parsedMessage,
|
|
365
363
|
this.ack(channel, msg, true),
|
|
@@ -413,7 +411,6 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
413
411
|
RabbitMq.validateName('queue', queue);
|
|
414
412
|
const channel: ChannelWrapper = await this.assertChannel();
|
|
415
413
|
await this.assertQueue(queue, options);
|
|
416
|
-
logger.info('rabbit: sending to queue', { queue, content, customHeaders });
|
|
417
414
|
return channel.sendToQueue(queue,
|
|
418
415
|
Buffer.from(JSON.stringify(content)),
|
|
419
416
|
RabbitMq.getPublishOptions(customHeaders));
|