@autofleet/rabbit 2.5.0-beta.4 → 2.5.0-beta.6
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 +28 -4
- package/package.json +2 -4
- package/src/index.ts +27 -4
package/dist/index.js
CHANGED
|
@@ -10,7 +10,7 @@ const redis_lock_1 = __importDefault(require("redis-lock"));
|
|
|
10
10
|
const amqp_connection_manager_1 = require("amqp-connection-manager");
|
|
11
11
|
const events_1 = require("events");
|
|
12
12
|
const util_1 = require("util");
|
|
13
|
-
const
|
|
13
|
+
const outbreak_1 = require("@autofleet/outbreak");
|
|
14
14
|
const logger_1 = __importDefault(require("./logger"));
|
|
15
15
|
const rabbitError_1 = __importDefault(require("./rabbitError"));
|
|
16
16
|
const redis_1 = __importDefault(require("./redis"));
|
|
@@ -124,7 +124,11 @@ class RabbitMq {
|
|
|
124
124
|
}
|
|
125
125
|
}
|
|
126
126
|
static getPublishOptions(customHeaders = {}) {
|
|
127
|
-
const trace =
|
|
127
|
+
const trace = outbreak_1.getCurrentContext();
|
|
128
|
+
logger_1.default.info('ANKRI getPublishOptions', {
|
|
129
|
+
trace,
|
|
130
|
+
context: Array.from(trace.context),
|
|
131
|
+
});
|
|
128
132
|
return {
|
|
129
133
|
timestamp: moment_1.default().unix(),
|
|
130
134
|
headers: {
|
|
@@ -256,8 +260,8 @@ class RabbitMq {
|
|
|
256
260
|
return null;
|
|
257
261
|
}
|
|
258
262
|
const traceId = msg.properties.headers[TRACING_HEADER];
|
|
259
|
-
const trace =
|
|
260
|
-
trace
|
|
263
|
+
const trace = outbreak_1.newTrace(outbreak_1.traceTypes.RABBIT);
|
|
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);
|
|
@@ -293,7 +297,17 @@ class RabbitMq {
|
|
|
293
297
|
});
|
|
294
298
|
}
|
|
295
299
|
async publish(exchange, content, customHeaders) {
|
|
300
|
+
const trace = outbreak_1.getCurrentContext();
|
|
301
|
+
logger_1.default.info('ANKRI publish', {
|
|
302
|
+
trace,
|
|
303
|
+
context: Array.from(trace.context),
|
|
304
|
+
});
|
|
296
305
|
return wrapSetImmediate(async () => {
|
|
306
|
+
const trace2 = outbreak_1.getCurrentContext();
|
|
307
|
+
logger_1.default.info('ANKRI publish inside wrapSetImmediate', {
|
|
308
|
+
trace: trace2,
|
|
309
|
+
context: Array.from(trace.context),
|
|
310
|
+
});
|
|
297
311
|
RabbitMq.validateName('exchange', exchange);
|
|
298
312
|
const channel = await this.assertChannel();
|
|
299
313
|
await this.assertExchange(exchange);
|
|
@@ -301,7 +315,17 @@ class RabbitMq {
|
|
|
301
315
|
});
|
|
302
316
|
}
|
|
303
317
|
async sendToQueue(queue, content, options, customHeaders) {
|
|
318
|
+
const trace = outbreak_1.getCurrentContext();
|
|
319
|
+
logger_1.default.info('ANKRI sendToQueue', {
|
|
320
|
+
trace,
|
|
321
|
+
context: Array.from(trace.context),
|
|
322
|
+
});
|
|
304
323
|
return wrapSetImmediate(async () => {
|
|
324
|
+
const trace2 = outbreak_1.getCurrentContext();
|
|
325
|
+
logger_1.default.info('ANKRI sendToQueue inside wrapSetImmediate', {
|
|
326
|
+
trace: trace2,
|
|
327
|
+
context: Array.from(trace.context),
|
|
328
|
+
});
|
|
305
329
|
RabbitMq.validateName('queue', queue);
|
|
306
330
|
const channel = await this.assertChannel();
|
|
307
331
|
await this.assertQueue(queue, options);
|
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.6",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -24,15 +24,13 @@
|
|
|
24
24
|
"moment": "^2.29.1",
|
|
25
25
|
"redis": "^3.1.2",
|
|
26
26
|
"redis-lock": "^0.1.4",
|
|
27
|
-
"shortid": "^2.2.16",
|
|
28
27
|
"uuid": "^8.3.2"
|
|
29
28
|
},
|
|
30
29
|
"peerDependencies": {
|
|
31
|
-
"@autofleet/
|
|
30
|
+
"@autofleet/outbreak": "*"
|
|
32
31
|
},
|
|
33
32
|
"devDependencies": {
|
|
34
33
|
"@types/jest": "^26.0.23",
|
|
35
|
-
"@types/shortid": "^0.0.29",
|
|
36
34
|
"@typescript-eslint/eslint-plugin": "^4.8.1",
|
|
37
35
|
"eslint": "^7.13.0",
|
|
38
36
|
"eslint-config-airbnb-typescript": "^12.0.0",
|
package/src/index.ts
CHANGED
|
@@ -2,12 +2,11 @@
|
|
|
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';
|
|
@@ -104,7 +103,11 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
104
103
|
}
|
|
105
104
|
|
|
106
105
|
static getPublishOptions(customHeaders: CustomMessageHeaders = {}) {
|
|
107
|
-
const trace =
|
|
106
|
+
const trace = getCurrentContext();
|
|
107
|
+
logger.info('ANKRI getPublishOptions', {
|
|
108
|
+
trace,
|
|
109
|
+
context: Array.from(trace.context),
|
|
110
|
+
});
|
|
108
111
|
return {
|
|
109
112
|
timestamp: moment().unix(),
|
|
110
113
|
headers: {
|
|
@@ -366,7 +369,7 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
366
369
|
|
|
367
370
|
const traceId = msg.properties.headers[TRACING_HEADER];
|
|
368
371
|
const trace = newTrace(traceTypes.RABBIT);
|
|
369
|
-
trace
|
|
372
|
+
(trace as any)?.context?.set(TRACING_HEADER, traceId);
|
|
370
373
|
|
|
371
374
|
const parsedMessage = RabbitMq.parseMsg(msg);
|
|
372
375
|
const releaseLock = await this.lockRedisIfNeeded(parsedMessage, optionsWithDefaults);
|
|
@@ -414,7 +417,17 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
414
417
|
}
|
|
415
418
|
|
|
416
419
|
async publish(exchange: string, content: any, customHeaders?: any) : Promise<boolean> {
|
|
420
|
+
const trace = getCurrentContext();
|
|
421
|
+
logger.info('ANKRI publish', {
|
|
422
|
+
trace,
|
|
423
|
+
context: Array.from(trace.context),
|
|
424
|
+
});
|
|
417
425
|
return wrapSetImmediate(async () => {
|
|
426
|
+
const trace2 = getCurrentContext();
|
|
427
|
+
logger.info('ANKRI publish inside wrapSetImmediate', {
|
|
428
|
+
trace: trace2,
|
|
429
|
+
context: Array.from(trace.context),
|
|
430
|
+
});
|
|
418
431
|
RabbitMq.validateName('exchange', exchange);
|
|
419
432
|
const channel: ChannelWrapper = await this.assertChannel();
|
|
420
433
|
await this.assertExchange(exchange);
|
|
@@ -425,7 +438,17 @@ class RabbitMq implements IAfRabbitMq {
|
|
|
425
438
|
}
|
|
426
439
|
|
|
427
440
|
async sendToQueue(queue: string, content: any, options?: any, customHeaders?: any) : Promise<boolean> {
|
|
441
|
+
const trace = getCurrentContext();
|
|
442
|
+
logger.info('ANKRI sendToQueue', {
|
|
443
|
+
trace,
|
|
444
|
+
context: Array.from(trace.context),
|
|
445
|
+
});
|
|
428
446
|
return wrapSetImmediate(async () => {
|
|
447
|
+
const trace2 = getCurrentContext();
|
|
448
|
+
logger.info('ANKRI sendToQueue inside wrapSetImmediate', {
|
|
449
|
+
trace: trace2,
|
|
450
|
+
context: Array.from(trace.context),
|
|
451
|
+
});
|
|
429
452
|
RabbitMq.validateName('queue', queue);
|
|
430
453
|
const channel: ChannelWrapper = await this.assertChannel();
|
|
431
454
|
await this.assertQueue(queue, options);
|