@autofleet/rabbit 2.1.4 → 2.1.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 -0
- package/dist/index.js +8 -3
- package/package.json +1 -1
- package/src/index.ts +7 -3
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
|
@@ -59,7 +59,7 @@ class RabbitMq {
|
|
|
59
59
|
const { properties: { timestamp, headers } } = msg;
|
|
60
60
|
if (timestamp && (headers === null || headers === void 0 ? void 0 : headers.redisTimestampValidationKey) && this.redisClient) {
|
|
61
61
|
const lastMessageTimestamp = yield this.redisClient.getAsync(headers.redisTimestampValidationKey);
|
|
62
|
-
return !lastMessageTimestamp ||
|
|
62
|
+
return !lastMessageTimestamp || moment_1.default(parseInt(lastMessageTimestamp, 10) * SECONDS_TO_MILLISECONDS).isBefore(moment_1.default(timestamp * SECONDS_TO_MILLISECONDS));
|
|
63
63
|
}
|
|
64
64
|
return true;
|
|
65
65
|
});
|
|
@@ -249,8 +249,7 @@ class RabbitMq {
|
|
|
249
249
|
outbreak_1.newTrace(outbreak_1.traceTypes.RABBIT);
|
|
250
250
|
const shouldConsume = yield this.shouldConsumeMessageByTimestamp(parsedMessage);
|
|
251
251
|
if (!shouldConsume) {
|
|
252
|
-
this.ack(channel);
|
|
253
|
-
return;
|
|
252
|
+
return this.ack(channel)(msg);
|
|
254
253
|
}
|
|
255
254
|
callback(parsedMessage, this.ack(channel, true), this.nack(channel, queue, optionsWithDefaults, { messageTtl: deadMessageTtl }));
|
|
256
255
|
})),
|
|
@@ -282,5 +281,11 @@ class RabbitMq {
|
|
|
282
281
|
return channel.sendToQueue(queue, Buffer.from(JSON.stringify(content)), RabbitMq.getPublishOptions(customHeaders));
|
|
283
282
|
});
|
|
284
283
|
}
|
|
284
|
+
isConnected() {
|
|
285
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
286
|
+
const connection = yield this.getConnection();
|
|
287
|
+
return connection.isConnected();
|
|
288
|
+
});
|
|
289
|
+
}
|
|
285
290
|
}
|
|
286
291
|
exports.default = RabbitMq;
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -110,7 +110,7 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
110
110
|
const { properties: { timestamp, headers } } = msg;
|
|
111
111
|
if (timestamp && headers?.redisTimestampValidationKey && this.redisClient) {
|
|
112
112
|
const lastMessageTimestamp = await this.redisClient.getAsync(headers.redisTimestampValidationKey);
|
|
113
|
-
return !lastMessageTimestamp ||
|
|
113
|
+
return !lastMessageTimestamp || moment(parseInt(lastMessageTimestamp, 10) * SECONDS_TO_MILLISECONDS).isBefore(moment(timestamp * SECONDS_TO_MILLISECONDS));
|
|
114
114
|
}
|
|
115
115
|
return true;
|
|
116
116
|
}
|
|
@@ -283,8 +283,7 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
283
283
|
newTrace(traceTypes.RABBIT);
|
|
284
284
|
const shouldConsume = await this.shouldConsumeMessageByTimestamp(parsedMessage);
|
|
285
285
|
if (!shouldConsume) {
|
|
286
|
-
this.ack(channel);
|
|
287
|
-
return;
|
|
286
|
+
return this.ack(channel)(msg);
|
|
288
287
|
}
|
|
289
288
|
callback(parsedMessage, this.ack(channel, true), this.nack(channel, queue, optionsWithDefaults, { messageTtl: deadMessageTtl }));
|
|
290
289
|
},
|
|
@@ -317,6 +316,11 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
317
316
|
Buffer.from(JSON.stringify(content)),
|
|
318
317
|
RabbitMq.getPublishOptions(customHeaders));
|
|
319
318
|
}
|
|
319
|
+
|
|
320
|
+
async isConnected() : Promise<boolean> {
|
|
321
|
+
const connection = await this.getConnection();
|
|
322
|
+
return connection.isConnected();
|
|
323
|
+
}
|
|
320
324
|
}
|
|
321
325
|
|
|
322
326
|
export default RabbitMq;
|