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