@autofleet/rabbit 3.0.1-beta → 3.0.1-beta1

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
@@ -126,13 +126,14 @@ class RabbitMq {
126
126
  static getPublishOptions(customHeaders = {}) {
127
127
  const trace = zehut_1.getCurrentPayload();
128
128
  const user = trace?.context?.get(consts_1.USER_OBJECT);
129
+ const outbreakTrace = zehut_1.oubtreak.getCurrentContext();
129
130
  return {
130
131
  timestamp: moment_1.default().unix(),
131
132
  headers: {
132
133
  creationTimestamp: moment_1.default().valueOf(),
133
134
  ...customHeaders,
134
135
  [consts_1.USER_TRACING_HEADER]: user?.id,
135
- [consts_1.TRACING_HEADER]: trace?.context?.get(consts_1.TRACING_HEADER),
136
+ [consts_1.TRACING_HEADER]: outbreakTrace?.context?.get(consts_1.TRACING_HEADER),
136
137
  },
137
138
  };
138
139
  }
@@ -339,23 +340,24 @@ class RabbitMq {
339
340
  const traceId = msg.properties.headers[consts_1.TRACING_HEADER];
340
341
  const userId = msg.properties.headers[consts_1.USER_TRACING_HEADER];
341
342
  logger_1.default.info('rabbit: consume', { traceId, userId, enableRabbitTrace });
343
+ const parsedMessage = RabbitMq.parseMsg(msg);
344
+ const releaseLock = await this.lockRedisIfNeeded(parsedMessage, optionsWithDefaults);
345
+ const trace = zehut_1.newTrace(zehut_1.traceTypes.RABBIT);
342
346
  if (traceId) {
343
- const trace = zehut_1.newTrace(zehut_1.traceTypes.RABBIT);
344
347
  trace?.context?.set(consts_1.TRACING_HEADER, traceId);
345
348
  }
346
- else if (userId && enableRabbitTrace) {
349
+ if (userId && enableRabbitTrace) {
347
350
  try {
348
- await zehut_1.setRabbitTrace(userId);
351
+ await zehut_1.createOrSetRabbitTrace(trace, userId);
349
352
  }
350
353
  catch (e) {
351
354
  logger_1.default.error('rabbit: failed to setRabbitTrace', { userId, e });
355
+ await this.nack(channel, queue, optionsWithDefaults, { messageTtl: deadMessageTtl }, msg, releaseLock)(msg);
352
356
  }
353
357
  }
354
358
  if (auditContext) {
355
- auditContext(queue);
359
+ await auditContext(queue);
356
360
  }
357
- const parsedMessage = RabbitMq.parseMsg(msg);
358
- const releaseLock = await this.lockRedisIfNeeded(parsedMessage, optionsWithDefaults);
359
361
  const shouldConsume = await this.shouldConsumeMessageByTimestamp(parsedMessage);
360
362
  if (!shouldConsume) {
361
363
  await this.unlockRedisIfNeeded(releaseLock);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autofleet/rabbit",
3
- "version": "3.0.1-beta",
3
+ "version": "3.0.1-beta1",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -16,7 +16,7 @@
16
16
  },
17
17
  "dependencies": {
18
18
  "@autofleet/logger": "^1.2.8",
19
- "@autofleet/zehut": "^3.0.1-beta",
19
+ "@autofleet/zehut": "^3.0.1-beta2",
20
20
  "@types/amqplib": "0.8.2",
21
21
  "@types/uuid": "^8.3.3",
22
22
  "amqp-connection-manager": "4.1.9",
package/src/index.ts CHANGED
@@ -9,7 +9,7 @@ import {
9
9
  ConfirmChannel, ConsumeMessage, Options, Replies,
10
10
  } from 'amqplib';
11
11
  import {
12
- getCurrentPayload, newTrace, traceTypes, setRabbitTrace,
12
+ getCurrentPayload, newTrace, traceTypes, createOrSetRabbitTrace, oubtreak,
13
13
  } from '@autofleet/zehut';
14
14
  import logger from './logger';
15
15
  import RabbitError from './lib/rabbitError';
@@ -114,13 +114,14 @@ class RabbitMq implements IAfRabbitMq {
114
114
  static getPublishOptions(customHeaders: CustomMessageHeaders = {}) {
115
115
  const trace = getCurrentPayload();
116
116
  const user = trace?.context?.get(USER_OBJECT);
117
+ const outbreakTrace = oubtreak.getCurrentContext();
117
118
  return {
118
119
  timestamp: moment().unix(),
119
120
  headers: {
120
121
  creationTimestamp: moment().valueOf(),
121
122
  ...customHeaders,
122
123
  [USER_TRACING_HEADER]: user?.id,
123
- [TRACING_HEADER]: trace?.context?.get(TRACING_HEADER),
124
+ [TRACING_HEADER]: outbreakTrace?.context?.get(TRACING_HEADER),
124
125
  },
125
126
  };
126
127
  }
@@ -483,23 +484,24 @@ class RabbitMq implements IAfRabbitMq {
483
484
  const traceId = msg.properties.headers[TRACING_HEADER];
484
485
  const userId = msg.properties.headers[USER_TRACING_HEADER];
485
486
  logger.info('rabbit: consume', { traceId, userId, enableRabbitTrace });
487
+ const parsedMessage = RabbitMq.parseMsg(msg);
488
+ const releaseLock = await this.lockRedisIfNeeded(parsedMessage, optionsWithDefaults);
489
+ const trace = newTrace(traceTypes.RABBIT);
486
490
  if (traceId) {
487
- const trace = newTrace(traceTypes.RABBIT);
488
491
  (trace as any)?.context?.set(TRACING_HEADER, traceId);
489
- } else if (userId && enableRabbitTrace) {
492
+ }
493
+ if (userId && enableRabbitTrace) {
490
494
  try {
491
- await setRabbitTrace(userId);
495
+ await createOrSetRabbitTrace(trace, userId);
492
496
  } catch (e) {
493
497
  logger.error('rabbit: failed to setRabbitTrace', { userId, e });
498
+ await this.nack(channel, queue, optionsWithDefaults, { messageTtl: deadMessageTtl }, msg, releaseLock)(msg);
494
499
  }
495
500
  }
496
501
 
497
502
  if (auditContext) {
498
- auditContext(queue);
503
+ await auditContext(queue);
499
504
  }
500
-
501
- const parsedMessage = RabbitMq.parseMsg(msg);
502
- const releaseLock = await this.lockRedisIfNeeded(parsedMessage, optionsWithDefaults);
503
505
  const shouldConsume = await this.shouldConsumeMessageByTimestamp(parsedMessage);
504
506
  if (!shouldConsume) {
505
507
  await this.unlockRedisIfNeeded(releaseLock);