@autofleet/rabbit 3.0.1-alpha10 → 3.0.1-alpha3

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 CHANGED
@@ -3,7 +3,7 @@ import { EventEmitter } from 'events';
3
3
  import { AmqpConnectionManager, ChannelWrapper } from 'amqp-connection-manager';
4
4
  import { ConfirmChannel, ConsumeMessage, Options, Replies } from 'amqplib';
5
5
  import { RedisConfig } from './lib/redis';
6
- import { TRACING_HEADER, USER_TRACING_HEADER } from './lib/consts';
6
+ import { TRACING_HEADER } from './lib/consts';
7
7
  import { CallbackFunction, ConsumeMessageOrNull, ConsumeOptions, CustomMessageHeaders, QueuesCache, RedisLockType, ExchangesCache } from './lib/types';
8
8
  export interface IAfRabbitMq {
9
9
  ack: any;
@@ -44,7 +44,6 @@ declare class RabbitMq implements IAfRabbitMq {
44
44
  static getPublishOptions(customHeaders?: CustomMessageHeaders): {
45
45
  timestamp: number;
46
46
  headers: {
47
- "x-af-user-id": any;
48
47
  "x-trace-id": any;
49
48
  redisTimestampValidationKey?: string | undefined;
50
49
  creationTimestamp: number;
package/dist/index.js CHANGED
@@ -125,13 +125,11 @@ class RabbitMq {
125
125
  }
126
126
  static getPublishOptions(customHeaders = {}) {
127
127
  const trace = zehut_1.getCurrentPayload();
128
- const user = trace?.context?.get(consts_1.USER_OBJECT);
129
128
  return {
130
129
  timestamp: moment_1.default().unix(),
131
130
  headers: {
132
131
  creationTimestamp: moment_1.default().valueOf(),
133
132
  ...customHeaders,
134
- [consts_1.USER_TRACING_HEADER]: user?.id,
135
133
  [consts_1.TRACING_HEADER]: trace?.context?.get(consts_1.TRACING_HEADER),
136
134
  },
137
135
  };
@@ -321,7 +319,7 @@ class RabbitMq {
321
319
  async consumeFromRabbit(queue, callback, options) {
322
320
  const optionsWithDefaults = { ...consts_1.DEFAULT_OPTIONS, ...options };
323
321
  RabbitMq.validateName('queue', queue);
324
- const { limit, deadMessageTtl, useConsumeWithLock, lockTimeout, auditContext, enableRabbitTrace, } = optionsWithDefaults;
322
+ const { limit, deadMessageTtl, useConsumeWithLock, lockTimeout, auditContext, } = optionsWithDefaults;
325
323
  if (useConsumeWithLock) {
326
324
  if (!this.redisLock) {
327
325
  throw new Error('Usage of consumeWithLock requires RedisInstance');
@@ -337,19 +335,12 @@ class RabbitMq {
337
335
  return null;
338
336
  }
339
337
  const traceId = msg.properties.headers[consts_1.TRACING_HEADER];
340
- const userId = msg.properties.headers[consts_1.USER_TRACING_HEADER];
341
- logger_1.default.info('rabbit: consume', { traceId, userId, enableRabbitTrace });
342
338
  if (traceId) {
343
339
  const trace = zehut_1.newTrace(zehut_1.traceTypes.RABBIT);
344
340
  trace?.context?.set(consts_1.TRACING_HEADER, traceId);
345
- }
346
- else if (userId && enableRabbitTrace) {
347
- try {
348
- await zehut_1.setRabbitTrace(userId);
349
- }
350
- catch (e) {
351
- logger_1.default.error('rabbit: failed to setRabbitTrace', { userId, e });
352
- }
341
+ logger_1.default.info(`rabbit: [consume] received message with traceId ${traceId}`, {
342
+ trace,
343
+ });
353
344
  }
354
345
  if (auditContext) {
355
346
  auditContext(queue);
@@ -2,8 +2,6 @@ export declare const DEFAULT_DEAD_TTL_TWO_DAYS: number;
2
2
  export declare const DEFAULT_LOCK_TIMEOUT: number;
3
3
  export declare const RETRY_HEADER = "x-retry-count";
4
4
  export declare const TRACING_HEADER = "x-trace-id";
5
- export declare const USER_TRACING_HEADER = "x-af-user-id";
6
- export declare const USER_OBJECT = "userObject";
7
5
  export declare const DEFAULT_USE_CONSUME_WITH_LOCK = false;
8
6
  export declare const CONNECTION_CREATED_CONST = "connectionCreated";
9
7
  export declare const DEFAULT_OPTIONS: {
@@ -13,5 +11,4 @@ export declare const DEFAULT_OPTIONS: {
13
11
  lockTimeout: number;
14
12
  useConsumeWithLock: boolean;
15
13
  auditContext: null;
16
- enableRabbitTrace: boolean;
17
14
  };
@@ -1,12 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DEFAULT_OPTIONS = exports.CONNECTION_CREATED_CONST = exports.DEFAULT_USE_CONSUME_WITH_LOCK = exports.USER_OBJECT = exports.USER_TRACING_HEADER = exports.TRACING_HEADER = exports.RETRY_HEADER = exports.DEFAULT_LOCK_TIMEOUT = exports.DEFAULT_DEAD_TTL_TWO_DAYS = void 0;
3
+ exports.DEFAULT_OPTIONS = exports.CONNECTION_CREATED_CONST = exports.DEFAULT_USE_CONSUME_WITH_LOCK = exports.TRACING_HEADER = exports.RETRY_HEADER = exports.DEFAULT_LOCK_TIMEOUT = exports.DEFAULT_DEAD_TTL_TWO_DAYS = void 0;
4
4
  exports.DEFAULT_DEAD_TTL_TWO_DAYS = 60000 * 60 * 12;
5
5
  exports.DEFAULT_LOCK_TIMEOUT = 1000 * 5;
6
6
  exports.RETRY_HEADER = 'x-retry-count';
7
7
  exports.TRACING_HEADER = 'x-trace-id';
8
- exports.USER_TRACING_HEADER = 'x-af-user-id';
9
- exports.USER_OBJECT = 'userObject';
10
8
  exports.DEFAULT_USE_CONSUME_WITH_LOCK = false;
11
9
  exports.CONNECTION_CREATED_CONST = 'connectionCreated';
12
10
  exports.DEFAULT_OPTIONS = {
@@ -16,5 +14,4 @@ exports.DEFAULT_OPTIONS = {
16
14
  lockTimeout: exports.DEFAULT_LOCK_TIMEOUT,
17
15
  useConsumeWithLock: exports.DEFAULT_USE_CONSUME_WITH_LOCK,
18
16
  auditContext: null,
19
- enableRabbitTrace: false,
20
17
  };
@@ -18,7 +18,6 @@ export interface ConsumeOptions {
18
18
  lockTimeout?: number;
19
19
  useConsumeWithLock?: boolean;
20
20
  auditContext?: any;
21
- enableRabbitTrace?: boolean;
22
21
  }
23
22
  export declare type CallbackFunction = (msg: ConsumeMessage, ack: any, nack: any) => Promise<any>;
24
23
  export declare type newChannelOpts = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autofleet/rabbit",
3
- "version": "3.0.1-alpha10",
3
+ "version": "3.0.1-alpha3",
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-alpha3",
19
+ "@autofleet/zehut": "^3.0.1",
20
20
  "@types/amqplib": "0.8.2",
21
21
  "@types/uuid": "^8.3.3",
22
22
  "amqp-connection-manager": "4.1.9",
@@ -27,6 +27,9 @@
27
27
  "redis-lock": "^0.1.4",
28
28
  "uuid": "^8.3.2"
29
29
  },
30
+ "peerDependencies": {
31
+ "@autofleet/outbreak": "^0.2.1"
32
+ },
30
33
  "devDependencies": {
31
34
  "@types/jest": "^26.0.23",
32
35
  "@typescript-eslint/eslint-plugin": "^4.8.1",
package/src/index.ts CHANGED
@@ -8,9 +8,7 @@ import { AmqpConnectionManager, ChannelWrapper, connect } from 'amqp-connection-
8
8
  import {
9
9
  ConfirmChannel, ConsumeMessage, Options, Replies,
10
10
  } from 'amqplib';
11
- import {
12
- getCurrentPayload, newTrace, traceTypes, setRabbitTrace,
13
- } from '@autofleet/zehut';
11
+ import { getCurrentPayload as getCurrentContext, newTrace, traceTypes } from '@autofleet/zehut';
14
12
  import logger from './logger';
15
13
  import RabbitError from './lib/rabbitError';
16
14
  import getRedisInstance, { RedisConfig } from './lib/redis';
@@ -21,8 +19,6 @@ import {
21
19
  DEFAULT_OPTIONS,
22
20
  RETRY_HEADER,
23
21
  TRACING_HEADER,
24
- USER_OBJECT,
25
- USER_TRACING_HEADER,
26
22
  } from './lib/consts';
27
23
  import {
28
24
  CallbackFunction,
@@ -112,14 +108,12 @@ class RabbitMq implements IAfRabbitMq {
112
108
  }
113
109
 
114
110
  static getPublishOptions(customHeaders: CustomMessageHeaders = {}) {
115
- const trace = getCurrentPayload();
116
- const user = trace?.context?.get(USER_OBJECT);
111
+ const trace = getCurrentContext();
117
112
  return {
118
113
  timestamp: moment().unix(),
119
114
  headers: {
120
115
  creationTimestamp: moment().valueOf(),
121
116
  ...customHeaders,
122
- [USER_TRACING_HEADER]: user?.id,
123
117
  [TRACING_HEADER]: trace?.context?.get(TRACING_HEADER),
124
118
  },
125
119
  };
@@ -461,7 +455,7 @@ class RabbitMq implements IAfRabbitMq {
461
455
  const optionsWithDefaults = { ...DEFAULT_OPTIONS, ...options };
462
456
  RabbitMq.validateName('queue', queue);
463
457
  const {
464
- limit, deadMessageTtl, useConsumeWithLock, lockTimeout, auditContext, enableRabbitTrace,
458
+ limit, deadMessageTtl, useConsumeWithLock, lockTimeout, auditContext,
465
459
  } = optionsWithDefaults;
466
460
  if (useConsumeWithLock) {
467
461
  if (!this.redisLock) {
@@ -481,17 +475,12 @@ class RabbitMq implements IAfRabbitMq {
481
475
  }
482
476
 
483
477
  const traceId = msg.properties.headers[TRACING_HEADER];
484
- const userId = msg.properties.headers[USER_TRACING_HEADER];
485
- logger.info('rabbit: consume', { traceId, userId, enableRabbitTrace });
486
478
  if (traceId) {
487
479
  const trace = newTrace(traceTypes.RABBIT);
488
480
  (trace as any)?.context?.set(TRACING_HEADER, traceId);
489
- } else if (userId && enableRabbitTrace) {
490
- try {
491
- await setRabbitTrace(userId);
492
- } catch (e) {
493
- logger.error('rabbit: failed to setRabbitTrace', { userId, e });
494
- }
481
+ logger.info(`rabbit: [consume] received message with traceId ${traceId}`, {
482
+ trace,
483
+ });
495
484
  }
496
485
 
497
486
  if (auditContext) {
package/src/lib/consts.ts CHANGED
@@ -2,8 +2,6 @@ export const DEFAULT_DEAD_TTL_TWO_DAYS = 60000 * 60 * 12;
2
2
  export const DEFAULT_LOCK_TIMEOUT = 1000 * 5;
3
3
  export const RETRY_HEADER = 'x-retry-count';
4
4
  export const TRACING_HEADER = 'x-trace-id';
5
- export const USER_TRACING_HEADER = 'x-af-user-id';
6
- export const USER_OBJECT = 'userObject';
7
5
  export const DEFAULT_USE_CONSUME_WITH_LOCK = false;
8
6
  export const CONNECTION_CREATED_CONST = 'connectionCreated';
9
7
  export const DEFAULT_OPTIONS = {
@@ -13,5 +11,4 @@ export const DEFAULT_OPTIONS = {
13
11
  lockTimeout: DEFAULT_LOCK_TIMEOUT,
14
12
  useConsumeWithLock: DEFAULT_USE_CONSUME_WITH_LOCK,
15
13
  auditContext: null,
16
- enableRabbitTrace: false,
17
14
  };
package/src/lib/types.ts CHANGED
@@ -22,7 +22,6 @@ export interface ConsumeOptions {
22
22
  lockTimeout?: number;
23
23
  useConsumeWithLock?: boolean;
24
24
  auditContext?: any;
25
- enableRabbitTrace?: boolean;
26
25
  }
27
26
 
28
27
  export type CallbackFunction = (msg: ConsumeMessage, ack: any, nack: any) => Promise<any>