@autofleet/rabbit 2.2.5 → 2.2.6
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 -8
- package/package.json +1 -1
- package/src/index.ts +10 -8
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
|
@@ -64,12 +64,14 @@ class RabbitMq {
|
|
|
64
64
|
}
|
|
65
65
|
return false;
|
|
66
66
|
});
|
|
67
|
-
this.ack = (channel, shouldUpdateRedisTimestamp = false) => (
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
67
|
+
this.ack = (channel, msg, shouldUpdateRedisTimestamp = false) => (userMsg) => __awaiter(this, void 0, void 0, function* () {
|
|
68
|
+
if (msg) {
|
|
69
|
+
yield channel.ack(msg);
|
|
70
|
+
const { properties: { timestamp, headers } } = msg;
|
|
71
|
+
if (shouldUpdateRedisTimestamp && timestamp && (headers === null || headers === void 0 ? void 0 : headers.redisTimestampValidationKey) && this.redisClient) {
|
|
72
|
+
const parsedTimestamp = parseInt(timestamp, 10);
|
|
73
|
+
yield this.redisClient.setAsync(headers.redisTimestampValidationKey, parsedTimestamp, 'EX', 3600);
|
|
74
|
+
}
|
|
73
75
|
}
|
|
74
76
|
});
|
|
75
77
|
this.nack = (channel, queue, options, deadQueueOptions, msg) => (userMsg, { skipRetry = false, } = {}) => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -282,10 +284,10 @@ class RabbitMq {
|
|
|
282
284
|
const shouldConsume = yield this.shouldConsumeMessageByTimestamp(parsedMessage);
|
|
283
285
|
logger_1.default.info('rabbit: trying to consume', { queue, shouldConsume, msg });
|
|
284
286
|
if (!shouldConsume) {
|
|
285
|
-
return this.ack(channel)(msg);
|
|
287
|
+
return this.ack(channel, msg)(msg);
|
|
286
288
|
}
|
|
287
289
|
try {
|
|
288
|
-
yield callback(parsedMessage, this.ack(channel, true), this.nack(channel, queue, optionsWithDefaults, { messageTtl: deadMessageTtl }, msg));
|
|
290
|
+
yield callback(parsedMessage, this.ack(channel, msg, true), this.nack(channel, queue, optionsWithDefaults, { messageTtl: deadMessageTtl }, msg));
|
|
289
291
|
}
|
|
290
292
|
catch (e) {
|
|
291
293
|
yield this.nack(channel, queue, optionsWithDefaults, { messageTtl: deadMessageTtl }, msg)(msg);
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -160,12 +160,14 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
160
160
|
return false;
|
|
161
161
|
}
|
|
162
162
|
|
|
163
|
-
public ack = (channel: ChannelWrapper, shouldUpdateRedisTimestamp = false) => async (
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
163
|
+
public ack = (channel: ChannelWrapper, msg: ConsumeMessageOrNull, shouldUpdateRedisTimestamp = false) => async (userMsg: ConsumeMessage) : Promise<any> => {
|
|
164
|
+
if (msg) {
|
|
165
|
+
await channel.ack(msg);
|
|
166
|
+
const { properties: { timestamp, headers } } = msg;
|
|
167
|
+
if (shouldUpdateRedisTimestamp && timestamp && headers?.redisTimestampValidationKey && this.redisClient) {
|
|
168
|
+
const parsedTimestamp = parseInt(timestamp, 10);
|
|
169
|
+
await this.redisClient.setAsync(headers.redisTimestampValidationKey, parsedTimestamp, 'EX', 3600);
|
|
170
|
+
}
|
|
169
171
|
}
|
|
170
172
|
}
|
|
171
173
|
|
|
@@ -355,12 +357,12 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
355
357
|
const shouldConsume = await this.shouldConsumeMessageByTimestamp(parsedMessage);
|
|
356
358
|
logger.info('rabbit: trying to consume', { queue, shouldConsume, msg });
|
|
357
359
|
if (!shouldConsume) {
|
|
358
|
-
return this.ack(channel)(msg);
|
|
360
|
+
return this.ack(channel, msg)(msg);
|
|
359
361
|
}
|
|
360
362
|
try {
|
|
361
363
|
await callback(
|
|
362
364
|
parsedMessage,
|
|
363
|
-
this.ack(channel, true),
|
|
365
|
+
this.ack(channel, msg, true),
|
|
364
366
|
this.nack(channel, queue, optionsWithDefaults, { messageTtl: deadMessageTtl }, msg),
|
|
365
367
|
);
|
|
366
368
|
} catch (e) {
|