@autofleet/rabbit 2.1.8 → 2.1.9

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 CHANGED
@@ -37,7 +37,7 @@ const bluebird = __importStar(require("bluebird"));
37
37
  const moment_1 = __importDefault(require("moment"));
38
38
  const amqp_connection_manager_1 = require("amqp-connection-manager");
39
39
  const events_1 = require("events");
40
- const outbreak_1 = require("@autofleet/outbreak");
40
+ // import { newTrace, traceTypes } from '@autofleet/outbreak';
41
41
  const logger_1 = __importDefault(require("./logger"));
42
42
  const rabbitError_1 = __importDefault(require("./rabbitError"));
43
43
  const redis_1 = __importDefault(require("./redis"));
@@ -123,7 +123,7 @@ class RabbitMq {
123
123
  return __awaiter(this, void 0, void 0, function* () {
124
124
  return new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
125
125
  if (this.creatingConnection) {
126
- this.em.on(connectionCreatedConst, resolve);
126
+ this.em.once(connectionCreatedConst, resolve);
127
127
  return;
128
128
  }
129
129
  if (this.connection !== null) {
@@ -163,8 +163,8 @@ class RabbitMq {
163
163
  if (this.channel) {
164
164
  return resolve(this.channel);
165
165
  }
166
- const connection = yield this.getConnection();
167
166
  try {
167
+ const connection = yield this.getConnection();
168
168
  if (this.channel === null) {
169
169
  this.channel = connection.createChannel({});
170
170
  }
@@ -223,13 +223,18 @@ class RabbitMq {
223
223
  return Promise.all([
224
224
  c.consume(queue, (msg) => __awaiter(this, void 0, void 0, function* () {
225
225
  const parsedMessage = RabbitMq.parseMsg(msg);
226
- outbreak_1.newTrace(outbreak_1.traceTypes.RABBIT);
226
+ // newTrace(traceTypes.RABBIT);
227
227
  const shouldConsume = yield this.shouldConsumeMessageByTimestamp(parsedMessage);
228
228
  logger_1.default.info('rabbit: trying to consume', { queue, shouldConsume, msg });
229
229
  if (!shouldConsume) {
230
230
  return this.ack(channel)(msg);
231
231
  }
232
- callback(parsedMessage, this.ack(channel, true), this.nack(channel, queue, optionsWithDefaults, { messageTtl: deadMessageTtl }));
232
+ try {
233
+ yield callback(parsedMessage, this.ack(channel, true), this.nack(channel, queue, optionsWithDefaults, { messageTtl: deadMessageTtl }));
234
+ }
235
+ catch (e) {
236
+ yield this.nack(channel, queue, optionsWithDefaults, { messageTtl: deadMessageTtl });
237
+ }
233
238
  })),
234
239
  ]);
235
240
  }));
@@ -251,7 +256,7 @@ class RabbitMq {
251
256
  c.bindQueue(queue, exchange, ''),
252
257
  c.consume(queue, (msg) => __awaiter(this, void 0, void 0, function* () {
253
258
  const parsedMessage = RabbitMq.parseMsg(msg);
254
- outbreak_1.newTrace(outbreak_1.traceTypes.RABBIT);
259
+ // newTrace(traceTypes.RABBIT);
255
260
  const shouldConsume = yield this.shouldConsumeMessageByTimestamp(parsedMessage);
256
261
  logger_1.default.info('rabbit: trying to consume', { queue, shouldConsume, msg });
257
262
  if (!shouldConsume) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autofleet/rabbit",
3
- "version": "2.1.8",
3
+ "version": "2.1.9",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
package/src/index.ts CHANGED
@@ -5,7 +5,7 @@ import moment from 'moment';
5
5
  import { ConfirmChannel, Options } 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
+ // import { newTrace, traceTypes } from '@autofleet/outbreak';
9
9
  import logger from './logger';
10
10
  import RabbitError from './rabbitError';
11
11
  import getRedisInstance, { RedisConfig } from './redis';
@@ -159,7 +159,7 @@ class RabbitMq implements IAfRabbitMq {
159
159
  async getConnection() {
160
160
  return new Promise<AmqpConnectionManager>(async (resolve) => {
161
161
  if (this.creatingConnection) {
162
- this.em.on(connectionCreatedConst, resolve);
162
+ this.em.once(connectionCreatedConst, resolve);
163
163
  return;
164
164
  }
165
165
  if (this.connection !== null) {
@@ -197,9 +197,8 @@ class RabbitMq implements IAfRabbitMq {
197
197
  return resolve(this.channel);
198
198
  }
199
199
 
200
- const connection: AmqpConnectionManager = await this.getConnection();
201
-
202
200
  try {
201
+ const connection: AmqpConnectionManager = await this.getConnection();
203
202
  if (this.channel === null) {
204
203
  this.channel = connection.createChannel({});
205
204
  }
@@ -254,13 +253,21 @@ class RabbitMq implements IAfRabbitMq {
254
253
  queue,
255
254
  async (msg: any) => {
256
255
  const parsedMessage = RabbitMq.parseMsg(msg);
257
- newTrace(traceTypes.RABBIT);
256
+ // newTrace(traceTypes.RABBIT);
258
257
  const shouldConsume = await this.shouldConsumeMessageByTimestamp(parsedMessage);
259
258
  logger.info('rabbit: trying to consume', { queue, shouldConsume, msg });
260
259
  if (!shouldConsume) {
261
260
  return this.ack(channel)(msg);
262
261
  }
263
- callback(parsedMessage, this.ack(channel, true), this.nack(channel, queue, optionsWithDefaults, { messageTtl: deadMessageTtl }));
262
+ try {
263
+ await callback(
264
+ parsedMessage,
265
+ this.ack(channel, true),
266
+ this.nack(channel, queue, optionsWithDefaults, { messageTtl: deadMessageTtl }),
267
+ );
268
+ } catch (e) {
269
+ await this.nack(channel, queue, optionsWithDefaults, { messageTtl: deadMessageTtl });
270
+ }
264
271
  },
265
272
  ),
266
273
  ]);
@@ -285,7 +292,7 @@ class RabbitMq implements IAfRabbitMq {
285
292
  queue,
286
293
  async (msg: any) => {
287
294
  const parsedMessage = RabbitMq.parseMsg(msg);
288
- newTrace(traceTypes.RABBIT);
295
+ // newTrace(traceTypes.RABBIT);
289
296
  const shouldConsume = await this.shouldConsumeMessageByTimestamp(parsedMessage);
290
297
  logger.info('rabbit: trying to consume', { queue, shouldConsume, msg });
291
298
  if (!shouldConsume) {