@autofleet/rabbit 2.1.14 → 2.1.16-beta
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 +16 -12
- package/package.json +1 -1
- package/src/index.ts +20 -15
package/dist/index.js
CHANGED
|
@@ -118,6 +118,8 @@ class RabbitMq {
|
|
|
118
118
|
this.connection = connection;
|
|
119
119
|
this.connection.on('disconnect', ({ err }) => {
|
|
120
120
|
var _a;
|
|
121
|
+
this.exchanges = {};
|
|
122
|
+
this.queues = {};
|
|
121
123
|
if ((_a = this.options) === null || _a === void 0 ? void 0 : _a.reconnect) {
|
|
122
124
|
console.error(`${this.RESCONNECT_MSG}${err && ` - ${err}`}`);
|
|
123
125
|
this.connection = null;
|
|
@@ -206,18 +208,20 @@ class RabbitMq {
|
|
|
206
208
|
yield c.prefetch(limit, true);
|
|
207
209
|
return Promise.all([
|
|
208
210
|
c.consume(queue, (msg) => __awaiter(this, void 0, void 0, function* () {
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
211
|
+
if (msg) {
|
|
212
|
+
const parsedMessage = RabbitMq.parseMsg(msg);
|
|
213
|
+
// newTrace(traceTypes.RABBIT);
|
|
214
|
+
const shouldConsume = yield this.shouldConsumeMessageByTimestamp(parsedMessage);
|
|
215
|
+
logger_1.default.info('rabbit: trying to consume', { queue, shouldConsume, msg });
|
|
216
|
+
if (!shouldConsume) {
|
|
217
|
+
return this.ack(channel)(msg);
|
|
218
|
+
}
|
|
219
|
+
try {
|
|
220
|
+
yield callback(parsedMessage, this.ack(channel, true), this.nack(channel, queue, optionsWithDefaults, { messageTtl: deadMessageTtl }));
|
|
221
|
+
}
|
|
222
|
+
catch (e) {
|
|
223
|
+
yield this.nack(channel, queue, optionsWithDefaults, { messageTtl: deadMessageTtl })(msg);
|
|
224
|
+
}
|
|
221
225
|
}
|
|
222
226
|
})),
|
|
223
227
|
]);
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -178,6 +178,8 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
178
178
|
this.connection = connection;
|
|
179
179
|
this.connection.on('disconnect',
|
|
180
180
|
({ err }) => {
|
|
181
|
+
this.exchanges = {};
|
|
182
|
+
this.queues = {};
|
|
181
183
|
if (this.options?.reconnect) {
|
|
182
184
|
console.error(`${this.RESCONNECT_MSG}${err && ` - ${err}`}`);
|
|
183
185
|
this.connection = null;
|
|
@@ -260,23 +262,26 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
260
262
|
c.consume(
|
|
261
263
|
queue,
|
|
262
264
|
async (msg: any) => {
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
265
|
+
if (msg) {
|
|
266
|
+
const parsedMessage = RabbitMq.parseMsg(msg);
|
|
267
|
+
// newTrace(traceTypes.RABBIT);
|
|
268
|
+
const shouldConsume = await this.shouldConsumeMessageByTimestamp(parsedMessage);
|
|
269
|
+
logger.info('rabbit: trying to consume', { queue, shouldConsume, msg });
|
|
270
|
+
if (!shouldConsume) {
|
|
271
|
+
return this.ack(channel)(msg);
|
|
272
|
+
}
|
|
273
|
+
try {
|
|
274
|
+
await callback(
|
|
275
|
+
parsedMessage,
|
|
276
|
+
this.ack(channel, true),
|
|
277
|
+
this.nack(channel, queue, optionsWithDefaults, { messageTtl: deadMessageTtl }),
|
|
278
|
+
);
|
|
279
|
+
} catch (e) {
|
|
280
|
+
await this.nack(channel, queue, optionsWithDefaults, { messageTtl: deadMessageTtl })(msg);
|
|
281
|
+
}
|
|
278
282
|
}
|
|
279
283
|
},
|
|
284
|
+
|
|
280
285
|
),
|
|
281
286
|
]);
|
|
282
287
|
});
|