@autofleet/rabbit 3.0.1-alpha6 → 3.0.1-alpha8
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 +2 -1
- package/dist/index.js +5 -9
- package/dist/lib/consts.d.ts +2 -0
- package/dist/lib/consts.js +3 -1
- package/package.json +2 -2
- package/src/index.ts +10 -12
- package/src/lib/consts.ts +2 -0
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 } from './lib/consts';
|
|
6
|
+
import { TRACING_HEADER, USER_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,6 +44,7 @@ declare class RabbitMq implements IAfRabbitMq {
|
|
|
44
44
|
static getPublishOptions(customHeaders?: CustomMessageHeaders): {
|
|
45
45
|
timestamp: number;
|
|
46
46
|
headers: {
|
|
47
|
+
"x-af-user-id": any;
|
|
47
48
|
"x-trace-id": any;
|
|
48
49
|
redisTimestampValidationKey?: string | undefined;
|
|
49
50
|
creationTimestamp: number;
|
package/dist/index.js
CHANGED
|
@@ -125,16 +125,13 @@ class RabbitMq {
|
|
|
125
125
|
}
|
|
126
126
|
static getPublishOptions(customHeaders = {}) {
|
|
127
127
|
const trace = zehut_1.getCurrentPayload();
|
|
128
|
-
|
|
129
|
-
trace,
|
|
130
|
-
context1: trace?.context?.get(consts_1.TRACING_HEADER),
|
|
131
|
-
context2: trace?.context?.get('userObject'),
|
|
132
|
-
});
|
|
128
|
+
const user = trace?.context?.get(consts_1.USER_OBJECT);
|
|
133
129
|
return {
|
|
134
130
|
timestamp: moment_1.default().unix(),
|
|
135
131
|
headers: {
|
|
136
132
|
creationTimestamp: moment_1.default().valueOf(),
|
|
137
133
|
...customHeaders,
|
|
134
|
+
[consts_1.USER_TRACING_HEADER]: user?.id,
|
|
138
135
|
[consts_1.TRACING_HEADER]: trace?.context?.get(consts_1.TRACING_HEADER),
|
|
139
136
|
},
|
|
140
137
|
};
|
|
@@ -340,14 +337,13 @@ class RabbitMq {
|
|
|
340
337
|
return null;
|
|
341
338
|
}
|
|
342
339
|
const traceId = msg.properties.headers[consts_1.TRACING_HEADER];
|
|
340
|
+
const userId = msg.properties.headers[consts_1.USER_TRACING_HEADER];
|
|
343
341
|
if (traceId) {
|
|
344
342
|
const trace = zehut_1.newTrace(zehut_1.traceTypes.RABBIT);
|
|
345
343
|
trace?.context?.set(consts_1.TRACING_HEADER, traceId);
|
|
346
|
-
logger_1.default.info(`rabbit: [consume] received message with traceId ${traceId}`, {
|
|
347
|
-
trace,
|
|
348
|
-
});
|
|
349
344
|
}
|
|
350
|
-
if (auditContext) {
|
|
345
|
+
else if (userId && auditContext) {
|
|
346
|
+
await zehut_1.setRabbitTrace(userId);
|
|
351
347
|
auditContext(queue);
|
|
352
348
|
}
|
|
353
349
|
const parsedMessage = RabbitMq.parseMsg(msg);
|
package/dist/lib/consts.d.ts
CHANGED
|
@@ -2,6 +2,8 @@ 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";
|
|
5
7
|
export declare const DEFAULT_USE_CONSUME_WITH_LOCK = false;
|
|
6
8
|
export declare const CONNECTION_CREATED_CONST = "connectionCreated";
|
|
7
9
|
export declare const DEFAULT_OPTIONS: {
|
package/dist/lib/consts.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
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.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.USER_OBJECT = exports.USER_TRACING_HEADER = 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';
|
|
8
10
|
exports.DEFAULT_USE_CONSUME_WITH_LOCK = false;
|
|
9
11
|
exports.CONNECTION_CREATED_CONST = 'connectionCreated';
|
|
10
12
|
exports.DEFAULT_OPTIONS = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@autofleet/rabbit",
|
|
3
|
-
"version": "3.0.1-
|
|
3
|
+
"version": "3.0.1-alpha8",
|
|
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",
|
|
19
|
+
"@autofleet/zehut": "^3.0.1-alpha3",
|
|
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
|
@@ -8,7 +8,9 @@ import { AmqpConnectionManager, ChannelWrapper, connect } from 'amqp-connection-
|
|
|
8
8
|
import {
|
|
9
9
|
ConfirmChannel, ConsumeMessage, Options, Replies,
|
|
10
10
|
} from 'amqplib';
|
|
11
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
getCurrentPayload, newTrace, traceTypes, setRabbitTrace,
|
|
13
|
+
} from '@autofleet/zehut';
|
|
12
14
|
import logger from './logger';
|
|
13
15
|
import RabbitError from './lib/rabbitError';
|
|
14
16
|
import getRedisInstance, { RedisConfig } from './lib/redis';
|
|
@@ -19,6 +21,8 @@ import {
|
|
|
19
21
|
DEFAULT_OPTIONS,
|
|
20
22
|
RETRY_HEADER,
|
|
21
23
|
TRACING_HEADER,
|
|
24
|
+
USER_OBJECT,
|
|
25
|
+
USER_TRACING_HEADER,
|
|
22
26
|
} from './lib/consts';
|
|
23
27
|
import {
|
|
24
28
|
CallbackFunction,
|
|
@@ -109,16 +113,13 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
109
113
|
|
|
110
114
|
static getPublishOptions(customHeaders: CustomMessageHeaders = {}) {
|
|
111
115
|
const trace = getCurrentPayload();
|
|
112
|
-
|
|
113
|
-
trace,
|
|
114
|
-
context1: trace?.context?.get(TRACING_HEADER),
|
|
115
|
-
context2: trace?.context?.get('userObject'),
|
|
116
|
-
});
|
|
116
|
+
const user = trace?.context?.get(USER_OBJECT);
|
|
117
117
|
return {
|
|
118
118
|
timestamp: moment().unix(),
|
|
119
119
|
headers: {
|
|
120
120
|
creationTimestamp: moment().valueOf(),
|
|
121
121
|
...customHeaders,
|
|
122
|
+
[USER_TRACING_HEADER]: user?.id,
|
|
122
123
|
[TRACING_HEADER]: trace?.context?.get(TRACING_HEADER),
|
|
123
124
|
},
|
|
124
125
|
};
|
|
@@ -480,15 +481,12 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
480
481
|
}
|
|
481
482
|
|
|
482
483
|
const traceId = msg.properties.headers[TRACING_HEADER];
|
|
484
|
+
const userId = msg.properties.headers[USER_TRACING_HEADER];
|
|
483
485
|
if (traceId) {
|
|
484
486
|
const trace = newTrace(traceTypes.RABBIT);
|
|
485
487
|
(trace as any)?.context?.set(TRACING_HEADER, traceId);
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
});
|
|
489
|
-
}
|
|
490
|
-
|
|
491
|
-
if (auditContext) {
|
|
488
|
+
} else if (userId && auditContext) {
|
|
489
|
+
await setRabbitTrace(userId);
|
|
492
490
|
auditContext(queue);
|
|
493
491
|
}
|
|
494
492
|
|
package/src/lib/consts.ts
CHANGED
|
@@ -2,6 +2,8 @@ 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';
|
|
5
7
|
export const DEFAULT_USE_CONSUME_WITH_LOCK = false;
|
|
6
8
|
export const CONNECTION_CREATED_CONST = 'connectionCreated';
|
|
7
9
|
export const DEFAULT_OPTIONS = {
|