@autofleet/rabbit 2.2.5 → 2.2.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 -1
- package/dist/index.js +10 -13
- package/package.json +1 -1
- package/src/index.ts +10 -13
package/dist/index.d.ts
CHANGED
|
@@ -59,7 +59,7 @@ declare class RabbitMq implements IAfRabbitMq {
|
|
|
59
59
|
redisLock?: RedisLockType;
|
|
60
60
|
constructor(options?: AfRabbitOptions, redisConfig?: RedisConfig);
|
|
61
61
|
private shouldConsumeMessageByTimestamp;
|
|
62
|
-
ack: (channel: ChannelWrapper, shouldUpdateRedisTimestamp?: boolean) => (
|
|
62
|
+
ack: (channel: ChannelWrapper, msg: ConsumeMessageOrNull, shouldUpdateRedisTimestamp?: boolean) => (userMsg: ConsumeMessage) => Promise<any>;
|
|
63
63
|
nack: (channel: ChannelWrapper, queue: string, options: any, deadQueueOptions: Options.AssertQueue, msg: ConsumeMessageOrNull) => (userMsg: ConsumeMessageOrNull, { skipRetry, }?: any) => Promise<any>;
|
|
64
64
|
getConnection(): Promise<AmqpConnectionManager>;
|
|
65
65
|
getNewChannel(): Promise<ChannelWrapper>;
|
package/dist/index.js
CHANGED
|
@@ -55,21 +55,20 @@ class RabbitMq {
|
|
|
55
55
|
const { properties: { timestamp, headers } } = msg;
|
|
56
56
|
if (timestamp && (headers === null || headers === void 0 ? void 0 : headers.redisTimestampValidationKey) && this.redisClient) {
|
|
57
57
|
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
58
|
return !lastMessageTimestamp || (parseInt(lastMessageTimestamp, 10) <= parseInt(timestamp, 10));
|
|
62
59
|
}
|
|
63
60
|
return true;
|
|
64
61
|
}
|
|
65
62
|
return false;
|
|
66
63
|
});
|
|
67
|
-
this.ack = (channel, shouldUpdateRedisTimestamp = false) => (
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
64
|
+
this.ack = (channel, msg, shouldUpdateRedisTimestamp = false) => (userMsg) => __awaiter(this, void 0, void 0, function* () {
|
|
65
|
+
if (msg) {
|
|
66
|
+
yield channel.ack(msg);
|
|
67
|
+
const { properties: { timestamp, headers } } = msg;
|
|
68
|
+
if (shouldUpdateRedisTimestamp && timestamp && (headers === null || headers === void 0 ? void 0 : headers.redisTimestampValidationKey) && this.redisClient) {
|
|
69
|
+
const parsedTimestamp = parseInt(timestamp, 10);
|
|
70
|
+
yield this.redisClient.setAsync(headers.redisTimestampValidationKey, parsedTimestamp, 'EX', 3600);
|
|
71
|
+
}
|
|
73
72
|
}
|
|
74
73
|
});
|
|
75
74
|
this.nack = (channel, queue, options, deadQueueOptions, msg) => (userMsg, { skipRetry = false, } = {}) => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -280,12 +279,11 @@ class RabbitMq {
|
|
|
280
279
|
}
|
|
281
280
|
const parsedMessage = RabbitMq.parseMsg(msg);
|
|
282
281
|
const shouldConsume = yield this.shouldConsumeMessageByTimestamp(parsedMessage);
|
|
283
|
-
logger_1.default.info('rabbit: trying to consume', { queue, shouldConsume, msg });
|
|
284
282
|
if (!shouldConsume) {
|
|
285
|
-
return this.ack(channel)(msg);
|
|
283
|
+
return this.ack(channel, msg)(msg);
|
|
286
284
|
}
|
|
287
285
|
try {
|
|
288
|
-
yield callback(parsedMessage, this.ack(channel, true), this.nack(channel, queue, optionsWithDefaults, { messageTtl: deadMessageTtl }, msg));
|
|
286
|
+
yield callback(parsedMessage, this.ack(channel, msg, true), this.nack(channel, queue, optionsWithDefaults, { messageTtl: deadMessageTtl }, msg));
|
|
289
287
|
}
|
|
290
288
|
catch (e) {
|
|
291
289
|
yield this.nack(channel, queue, optionsWithDefaults, { messageTtl: deadMessageTtl }, msg)(msg);
|
|
@@ -330,7 +328,6 @@ class RabbitMq {
|
|
|
330
328
|
RabbitMq.validateName('queue', queue);
|
|
331
329
|
const channel = yield this.assertChannel();
|
|
332
330
|
yield this.assertQueue(queue, options);
|
|
333
|
-
logger_1.default.info('rabbit: sending to queue', { queue, content, customHeaders });
|
|
334
331
|
return channel.sendToQueue(queue, Buffer.from(JSON.stringify(content)), RabbitMq.getPublishOptions(customHeaders));
|
|
335
332
|
}));
|
|
336
333
|
});
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -150,9 +150,6 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
150
150
|
const { properties: { timestamp, headers } } = msg;
|
|
151
151
|
if (timestamp && headers?.redisTimestampValidationKey && this.redisClient) {
|
|
152
152
|
const lastMessageTimestamp = await this.redisClient.getAsync(headers.redisTimestampValidationKey);
|
|
153
|
-
logger.info('rabbit: checking if should consume params', {
|
|
154
|
-
msg, timestamp, headers, lastMessageTimestamp,
|
|
155
|
-
});
|
|
156
153
|
return !lastMessageTimestamp || (parseInt(lastMessageTimestamp, 10) <= parseInt(timestamp, 10));
|
|
157
154
|
}
|
|
158
155
|
return true;
|
|
@@ -160,12 +157,14 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
160
157
|
return false;
|
|
161
158
|
}
|
|
162
159
|
|
|
163
|
-
public ack = (channel: ChannelWrapper, shouldUpdateRedisTimestamp = false) => async (
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
160
|
+
public ack = (channel: ChannelWrapper, msg: ConsumeMessageOrNull, shouldUpdateRedisTimestamp = false) => async (userMsg: ConsumeMessage) : Promise<any> => {
|
|
161
|
+
if (msg) {
|
|
162
|
+
await channel.ack(msg);
|
|
163
|
+
const { properties: { timestamp, headers } } = msg;
|
|
164
|
+
if (shouldUpdateRedisTimestamp && timestamp && headers?.redisTimestampValidationKey && this.redisClient) {
|
|
165
|
+
const parsedTimestamp = parseInt(timestamp, 10);
|
|
166
|
+
await this.redisClient.setAsync(headers.redisTimestampValidationKey, parsedTimestamp, 'EX', 3600);
|
|
167
|
+
}
|
|
169
168
|
}
|
|
170
169
|
}
|
|
171
170
|
|
|
@@ -353,14 +352,13 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
353
352
|
}
|
|
354
353
|
const parsedMessage = RabbitMq.parseMsg(msg);
|
|
355
354
|
const shouldConsume = await this.shouldConsumeMessageByTimestamp(parsedMessage);
|
|
356
|
-
logger.info('rabbit: trying to consume', { queue, shouldConsume, msg });
|
|
357
355
|
if (!shouldConsume) {
|
|
358
|
-
return this.ack(channel)(msg);
|
|
356
|
+
return this.ack(channel, msg)(msg);
|
|
359
357
|
}
|
|
360
358
|
try {
|
|
361
359
|
await callback(
|
|
362
360
|
parsedMessage,
|
|
363
|
-
this.ack(channel, true),
|
|
361
|
+
this.ack(channel, msg, true),
|
|
364
362
|
this.nack(channel, queue, optionsWithDefaults, { messageTtl: deadMessageTtl }, msg),
|
|
365
363
|
);
|
|
366
364
|
} catch (e) {
|
|
@@ -411,7 +409,6 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
411
409
|
RabbitMq.validateName('queue', queue);
|
|
412
410
|
const channel: ChannelWrapper = await this.assertChannel();
|
|
413
411
|
await this.assertQueue(queue, options);
|
|
414
|
-
logger.info('rabbit: sending to queue', { queue, content, customHeaders });
|
|
415
412
|
return channel.sendToQueue(queue,
|
|
416
413
|
Buffer.from(JSON.stringify(content)),
|
|
417
414
|
RabbitMq.getPublishOptions(customHeaders));
|