@autofleet/rabbit 2.5.0-beta.10 → 2.5.0-beta.2
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 +1 -1
- package/dist/index.js +10 -6
- package/package.json +4 -4
- package/src/index.ts +10 -5
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { Options, ConsumeMessage } from 'amqplib';
|
|
|
3
3
|
import { AmqpConnectionManager, ChannelWrapper } from 'amqp-connection-manager';
|
|
4
4
|
import { EventEmitter } from 'events';
|
|
5
5
|
import { RedisConfig } from './redis';
|
|
6
|
+
declare const TRACING_HEADER = "x-trace-id";
|
|
6
7
|
export interface IAfRabbitMq {
|
|
7
8
|
ack: any;
|
|
8
9
|
nack: any;
|
|
@@ -37,7 +38,6 @@ declare type CallbackFunction = (msg: ConsumeMessage, ack: Function, nack: Funct
|
|
|
37
38
|
export interface AfRabbitOptions {
|
|
38
39
|
disableReconnect: boolean;
|
|
39
40
|
}
|
|
40
|
-
declare const TRACING_HEADER = "x-trace-id";
|
|
41
41
|
declare class RabbitMq implements IAfRabbitMq {
|
|
42
42
|
static parseMsg(msg: any): any;
|
|
43
43
|
static validateName(type: string, name: string): void;
|
package/dist/index.js
CHANGED
|
@@ -7,17 +7,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
7
7
|
// eslint-disable-next-line max-classes-per-file
|
|
8
8
|
const moment_1 = __importDefault(require("moment"));
|
|
9
9
|
const redis_lock_1 = __importDefault(require("redis-lock"));
|
|
10
|
+
const shortid_1 = __importDefault(require("shortid"));
|
|
10
11
|
const amqp_connection_manager_1 = require("amqp-connection-manager");
|
|
11
12
|
const events_1 = require("events");
|
|
12
13
|
const util_1 = require("util");
|
|
13
|
-
const
|
|
14
|
+
const zehut_1 = require("@autofleet/zehut");
|
|
14
15
|
const logger_1 = __importDefault(require("./logger"));
|
|
15
16
|
const rabbitError_1 = __importDefault(require("./rabbitError"));
|
|
16
17
|
const redis_1 = __importDefault(require("./redis"));
|
|
18
|
+
const TRACING_HEADER = 'x-trace-id';
|
|
17
19
|
const DEFAULT_DEAD_TTL_TWO_DAYS = 60000 * 60 * 48;
|
|
18
20
|
const DEFAULT_LOCK_TIMEOUT = 1000 * 5;
|
|
19
21
|
const RETRY_HEADER = 'x-retry-count';
|
|
20
|
-
const TRACING_HEADER = 'x-trace-id';
|
|
21
22
|
const DEFAULT_USE_CONSUME_WITH_LOCK = false;
|
|
22
23
|
const defaultOptions = {
|
|
23
24
|
limit: 1,
|
|
@@ -124,7 +125,7 @@ class RabbitMq {
|
|
|
124
125
|
}
|
|
125
126
|
}
|
|
126
127
|
static getPublishOptions(customHeaders = {}) {
|
|
127
|
-
const trace =
|
|
128
|
+
const trace = zehut_1.getCurrentPayload();
|
|
128
129
|
return {
|
|
129
130
|
timestamp: moment_1.default().unix(),
|
|
130
131
|
headers: {
|
|
@@ -255,9 +256,12 @@ class RabbitMq {
|
|
|
255
256
|
if (!msg) {
|
|
256
257
|
return null;
|
|
257
258
|
}
|
|
258
|
-
const
|
|
259
|
-
|
|
260
|
-
|
|
259
|
+
const trace = zehut_1.newTrace(zehut_1.traceTypes.RABBIT);
|
|
260
|
+
let traceId = msg.properties.headers[TRACING_HEADER];
|
|
261
|
+
if (typeof traceId === 'undefined') {
|
|
262
|
+
traceId = shortid_1.default.generate();
|
|
263
|
+
}
|
|
264
|
+
trace.context.set(TRACING_HEADER, traceId);
|
|
261
265
|
const parsedMessage = RabbitMq.parseMsg(msg);
|
|
262
266
|
const releaseLock = await this.lockRedisIfNeeded(parsedMessage, optionsWithDefaults);
|
|
263
267
|
const shouldConsume = await this.shouldConsumeMessageByTimestamp(parsedMessage);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@autofleet/rabbit",
|
|
3
|
-
"version": "2.5.0-beta.
|
|
3
|
+
"version": "2.5.0-beta.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"@autofleet/logger": "^1.2.8",
|
|
19
|
+
"@autofleet/zehut": "^3.0.0",
|
|
19
20
|
"@types/amqplib": "0.8.2",
|
|
20
21
|
"@types/uuid": "^8.3.3",
|
|
21
22
|
"amqp-connection-manager": "4.1.9",
|
|
@@ -24,13 +25,12 @@
|
|
|
24
25
|
"moment": "^2.29.1",
|
|
25
26
|
"redis": "^3.1.2",
|
|
26
27
|
"redis-lock": "^0.1.4",
|
|
28
|
+
"shortid": "^2.2.16",
|
|
27
29
|
"uuid": "^8.3.2"
|
|
28
30
|
},
|
|
29
|
-
"peerDependencies": {
|
|
30
|
-
"@autofleet/outbreak": "^0.2.1"
|
|
31
|
-
},
|
|
32
31
|
"devDependencies": {
|
|
33
32
|
"@types/jest": "^26.0.23",
|
|
33
|
+
"@types/shortid": "^0.0.29",
|
|
34
34
|
"@typescript-eslint/eslint-plugin": "^4.8.1",
|
|
35
35
|
"eslint": "^7.13.0",
|
|
36
36
|
"eslint-config-airbnb-typescript": "^12.0.0",
|
package/src/index.ts
CHANGED
|
@@ -2,15 +2,18 @@
|
|
|
2
2
|
// eslint-disable-next-line max-classes-per-file
|
|
3
3
|
import moment from 'moment';
|
|
4
4
|
import RedisLock from 'redis-lock';
|
|
5
|
+
import shortid from 'shortid';
|
|
5
6
|
import { ConfirmChannel, Options, ConsumeMessage } from 'amqplib';
|
|
6
7
|
import { AmqpConnectionManager, ChannelWrapper, connect } from 'amqp-connection-manager';
|
|
7
8
|
import { EventEmitter } from 'events';
|
|
8
9
|
import { promisify } from 'util';
|
|
9
|
-
import { traceTypes,
|
|
10
|
+
import { traceTypes, getCurrentPayload, newTrace } from '@autofleet/zehut';
|
|
10
11
|
import logger from './logger';
|
|
11
12
|
import RabbitError from './rabbitError';
|
|
12
13
|
import getRedisInstance, { RedisConfig } from './redis';
|
|
13
14
|
|
|
15
|
+
const TRACING_HEADER = 'x-trace-id';
|
|
16
|
+
|
|
14
17
|
export interface IAfRabbitMq {
|
|
15
18
|
ack: any;
|
|
16
19
|
nack: any;
|
|
@@ -55,7 +58,6 @@ export interface AfRabbitOptions {
|
|
|
55
58
|
const DEFAULT_DEAD_TTL_TWO_DAYS = 60000 * 60 * 48;
|
|
56
59
|
const DEFAULT_LOCK_TIMEOUT = 1000 * 5;
|
|
57
60
|
const RETRY_HEADER = 'x-retry-count';
|
|
58
|
-
const TRACING_HEADER = 'x-trace-id';
|
|
59
61
|
const DEFAULT_USE_CONSUME_WITH_LOCK = false;
|
|
60
62
|
|
|
61
63
|
const defaultOptions = {
|
|
@@ -103,7 +105,7 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
103
105
|
}
|
|
104
106
|
|
|
105
107
|
static getPublishOptions(customHeaders: CustomMessageHeaders = {}) {
|
|
106
|
-
const trace =
|
|
108
|
+
const trace = getCurrentPayload();
|
|
107
109
|
return {
|
|
108
110
|
timestamp: moment().unix(),
|
|
109
111
|
headers: {
|
|
@@ -363,9 +365,12 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
363
365
|
return null;
|
|
364
366
|
}
|
|
365
367
|
|
|
366
|
-
const traceId = msg.properties.headers[TRACING_HEADER];
|
|
367
368
|
const trace = newTrace(traceTypes.RABBIT);
|
|
368
|
-
|
|
369
|
+
let traceId = msg.properties.headers[TRACING_HEADER];
|
|
370
|
+
if (typeof traceId === 'undefined') {
|
|
371
|
+
traceId = shortid.generate();
|
|
372
|
+
}
|
|
373
|
+
trace.context.set(TRACING_HEADER, traceId);
|
|
369
374
|
|
|
370
375
|
const parsedMessage = RabbitMq.parseMsg(msg);
|
|
371
376
|
const releaseLock = await this.lockRedisIfNeeded(parsedMessage, optionsWithDefaults);
|