@diia-inhouse/diia-queue 14.2.38 → 14.2.40
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/providers/rabbitmq/amqpListener.js +1 -3
- package/dist/providers/rabbitmq/index.d.ts +1 -1
- package/dist/providers/rabbitmq/index.js +2 -2
- package/dist/services/eventCommunicator.js +3 -3
- package/dist/services/eventMessageHandler.d.ts +5 -1
- package/dist/services/eventMessageHandler.js +26 -11
- package/dist/services/index.js +1 -1
- package/dist/services/queue.d.ts +1 -1
- package/dist/services/task.js +5 -5
- package/package.json +4 -4
|
@@ -144,9 +144,7 @@ var AmqpListener = class {
|
|
|
144
144
|
}
|
|
145
145
|
const response = this.prepareResponse(message, messageData, channel);
|
|
146
146
|
try {
|
|
147
|
-
|
|
148
|
-
this.rabbitMQMetrics.collectResponseTotalMetric(startTime, eventName, source, this.systemServiceName);
|
|
149
|
-
return result;
|
|
147
|
+
return await callback(response);
|
|
150
148
|
} catch (callbackErr) {
|
|
151
149
|
const errorType = callbackErr instanceof ApiError ? callbackErr.getType() : ErrorType.Unoperated;
|
|
152
150
|
this.rabbitMQMetrics.collectResponseTotalMetric(startTime, eventName, source, this.systemServiceName, errorType);
|
|
@@ -9,9 +9,9 @@ import { QueueContext } from "../../interfaces/queueContext.js";
|
|
|
9
9
|
import { AmqpAsserter } from "./amqpAsserter.js";
|
|
10
10
|
import { AmqpListener } from "./amqpListener.js";
|
|
11
11
|
import { AmqpPublisher } from "./amqpPublisher.js";
|
|
12
|
+
import { MetricsService } from "@diia-inhouse/diia-metrics";
|
|
12
13
|
import { Logger } from "@diia-inhouse/types";
|
|
13
14
|
import { EventEmitter } from "node:events";
|
|
14
|
-
import { MetricsService } from "@diia-inhouse/diia-metrics";
|
|
15
15
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
16
16
|
|
|
17
17
|
//#region src/providers/rabbitmq/index.d.ts
|
|
@@ -8,7 +8,7 @@ import { AmqpAsserter } from "./amqpAsserter.js";
|
|
|
8
8
|
import { AmqpConnection } from "./amqpConnection.js";
|
|
9
9
|
import { AmqpListener } from "./amqpListener.js";
|
|
10
10
|
import { AmqpPublisher } from "./amqpPublisher.js";
|
|
11
|
-
import
|
|
11
|
+
import lodash from "lodash";
|
|
12
12
|
import { randomUUID } from "node:crypto";
|
|
13
13
|
import { EventEmitter } from "node:events";
|
|
14
14
|
//#region src/providers/rabbitmq/index.ts
|
|
@@ -112,7 +112,7 @@ var RabbitMQProvider = class extends EventEmitter {
|
|
|
112
112
|
};
|
|
113
113
|
}
|
|
114
114
|
async makeAMQPConnection(client) {
|
|
115
|
-
return new AmqpConnection(this.rabbitmqConfig.connection, this.logger, this.rabbitmqConfig.reconnectOptions,
|
|
115
|
+
return new AmqpConnection(this.rabbitmqConfig.connection, this.logger, this.rabbitmqConfig.reconnectOptions, lodash.merge({ clientProperties: { connectionClientType: client } }, this.rabbitmqConfig.socketOptions));
|
|
116
116
|
}
|
|
117
117
|
async makeAMQPListener(queuesOptions) {
|
|
118
118
|
return new AmqpListener(await this.getConnection("listener"), this.logger, this.rabbitMQMetricsService, queuesOptions, this.systemServiceName);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { collectEventBusListeners } from "../utils.js";
|
|
2
|
-
import
|
|
2
|
+
import lodash from "lodash";
|
|
3
3
|
//#region src/services/eventCommunicator.ts
|
|
4
4
|
var EventCommunicator = class {
|
|
5
5
|
logger;
|
|
@@ -33,8 +33,8 @@ var EventCommunicator = class {
|
|
|
33
33
|
getUnicastListeners() {
|
|
34
34
|
const listeners = [];
|
|
35
35
|
const { queuesOptions, exchangesOptions } = this.queueProvider.getMessageBrokerServiceConfig();
|
|
36
|
-
const queuesOptionsMap =
|
|
37
|
-
const exchangesOptionsMap =
|
|
36
|
+
const queuesOptionsMap = lodash.keyBy(queuesOptions, "name");
|
|
37
|
+
const exchangesOptionsMap = lodash.keyBy(exchangesOptions, "name");
|
|
38
38
|
for (const eventListener of this.listenerList) {
|
|
39
39
|
const { queueNames = [] } = eventListener;
|
|
40
40
|
for (const queueName of queueNames) {
|
|
@@ -2,6 +2,7 @@ import { QueueMessage } from "../interfaces/providers/rabbitmq/index.js";
|
|
|
2
2
|
import { QueueContext } from "../interfaces/queueContext.js";
|
|
3
3
|
import { EventBusListener, EventListeners, TaskListener } from "../interfaces/index.js";
|
|
4
4
|
import { EventMessageValidator } from "./eventMessageValidator.js";
|
|
5
|
+
import { MetricsService } from "@diia-inhouse/diia-metrics";
|
|
5
6
|
import Logger from "@diia-inhouse/diia-logger";
|
|
6
7
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
7
8
|
|
|
@@ -10,12 +11,15 @@ declare class EventMessageHandler {
|
|
|
10
11
|
private readonly eventMessageValidator;
|
|
11
12
|
private readonly asyncLocalStorage;
|
|
12
13
|
private readonly logger;
|
|
14
|
+
private readonly systemServiceName;
|
|
13
15
|
private readonly noRequeueNackOptions;
|
|
14
|
-
|
|
16
|
+
private readonly rabbitMQMetrics;
|
|
17
|
+
constructor(eventMessageValidator: EventMessageValidator, asyncLocalStorage: AsyncLocalStorage<QueueContext>, logger: Logger, systemServiceName: string, metrics: MetricsService);
|
|
15
18
|
eventListenersMessageHandler(this: this, eventListeners: EventListeners, message: QueueMessage | null): Promise<void>;
|
|
16
19
|
eventListenerMessageHandler(listener: EventBusListener | TaskListener | undefined, message: QueueMessage): Promise<void>;
|
|
17
20
|
private prepareAsyncContext;
|
|
18
21
|
private handleMessage;
|
|
22
|
+
private getErrorType;
|
|
19
23
|
private validateData;
|
|
20
24
|
private directReplyDone;
|
|
21
25
|
private getServiceCode;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { NackOptions } from "../interfaces/providers/rabbitmq/index.js";
|
|
1
|
+
import { Headers, NackOptions } from "../interfaces/providers/rabbitmq/index.js";
|
|
2
|
+
import "../interfaces/metrics/index.js";
|
|
2
3
|
import "../interfaces/index.js";
|
|
3
|
-
import
|
|
4
|
+
import RabbitMQMetricsService from "./metrics.js";
|
|
5
|
+
import { ApiError, ErrorType, ValidationError } from "@diia-inhouse/errors";
|
|
4
6
|
import { randomBytes } from "node:crypto";
|
|
5
7
|
import { context, isValidTraceId, propagation, trace } from "@opentelemetry/api";
|
|
6
8
|
import { utils } from "@diia-inhouse/utils";
|
|
@@ -9,11 +11,15 @@ var EventMessageHandler = class {
|
|
|
9
11
|
eventMessageValidator;
|
|
10
12
|
asyncLocalStorage;
|
|
11
13
|
logger;
|
|
14
|
+
systemServiceName;
|
|
12
15
|
noRequeueNackOptions = new NackOptions(false, false);
|
|
13
|
-
|
|
16
|
+
rabbitMQMetrics;
|
|
17
|
+
constructor(eventMessageValidator, asyncLocalStorage, logger, systemServiceName, metrics) {
|
|
14
18
|
this.eventMessageValidator = eventMessageValidator;
|
|
15
19
|
this.asyncLocalStorage = asyncLocalStorage;
|
|
16
20
|
this.logger = logger;
|
|
21
|
+
this.systemServiceName = systemServiceName;
|
|
22
|
+
this.rabbitMQMetrics = new RabbitMQMetricsService(metrics);
|
|
17
23
|
}
|
|
18
24
|
async eventListenersMessageHandler(eventListeners, message) {
|
|
19
25
|
if (!message) return;
|
|
@@ -21,17 +27,21 @@ var EventMessageHandler = class {
|
|
|
21
27
|
await this.eventListenerMessageHandler(listener, message);
|
|
22
28
|
}
|
|
23
29
|
async eventListenerMessageHandler(listener, message) {
|
|
30
|
+
const startTime = process.hrtime.bigint();
|
|
24
31
|
const { done, properties, data: { event, payload } } = message;
|
|
25
32
|
const serviceCode = this.getServiceCode(listener, payload);
|
|
26
33
|
const context = this.prepareAsyncContext(properties, serviceCode);
|
|
27
|
-
await this.asyncLocalStorage.run(context, async () => {
|
|
34
|
+
const errorType = await this.asyncLocalStorage.run(context, async () => {
|
|
28
35
|
this.logger.info(`Handling event [${event}] with payload`, { payload });
|
|
29
36
|
if (!listener) {
|
|
30
37
|
this.logger.info(`Not found listener for the event [${event}]`);
|
|
31
|
-
|
|
38
|
+
done();
|
|
39
|
+
return;
|
|
32
40
|
}
|
|
33
41
|
return await this.handleMessage(listener, message);
|
|
34
42
|
});
|
|
43
|
+
const source = properties.headers?.[Headers.sentFrom] || "unknown";
|
|
44
|
+
this.rabbitMQMetrics.collectResponseTotalMetric(startTime, event || "unknown", source, this.systemServiceName, errorType);
|
|
35
45
|
}
|
|
36
46
|
prepareAsyncContext(properties, serviceCode) {
|
|
37
47
|
return { logData: {
|
|
@@ -47,8 +57,9 @@ var EventMessageHandler = class {
|
|
|
47
57
|
let result;
|
|
48
58
|
const { isValid, error } = await this.validateData(data, listener);
|
|
49
59
|
if (!isValid) {
|
|
50
|
-
if (useDirectReply && error)
|
|
51
|
-
|
|
60
|
+
if (useDirectReply && error) this.directReplyDone(message, error, true);
|
|
61
|
+
else reject(this.noRequeueNackOptions);
|
|
62
|
+
return this.getErrorType(error);
|
|
52
63
|
}
|
|
53
64
|
try {
|
|
54
65
|
result = await listener.handler?.(payload, meta);
|
|
@@ -57,10 +68,14 @@ var EventMessageHandler = class {
|
|
|
57
68
|
hasErrorOccurred = true;
|
|
58
69
|
this.logger.error(`Failed to handle event ${event}`, { err });
|
|
59
70
|
}
|
|
60
|
-
if (useDirectReply)
|
|
61
|
-
if (result instanceof NackOptions)
|
|
62
|
-
else if (hasErrorOccurred && listener.nackOptions)
|
|
63
|
-
|
|
71
|
+
if (useDirectReply) this.directReplyDone(message, result, hasErrorOccurred);
|
|
72
|
+
else if (result instanceof NackOptions) reject(result);
|
|
73
|
+
else if (hasErrorOccurred && listener.nackOptions) reject(listener.nackOptions);
|
|
74
|
+
else done();
|
|
75
|
+
return hasErrorOccurred ? this.getErrorType(result) : void 0;
|
|
76
|
+
}
|
|
77
|
+
getErrorType(err) {
|
|
78
|
+
return err instanceof ApiError ? err.getType() : ErrorType.Unoperated;
|
|
64
79
|
}
|
|
65
80
|
async validateData(data, listener) {
|
|
66
81
|
const { payload } = data;
|
package/dist/services/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import "./eventBus.js";
|
|
2
|
+
import "./metrics.js";
|
|
2
3
|
import "./eventMessageHandler.js";
|
|
3
4
|
import "./eventMessageValidator.js";
|
|
4
5
|
import "./externalCommunicator.js";
|
|
5
6
|
import "./externalEventBus.js";
|
|
6
7
|
import "./scheduledTask.js";
|
|
7
8
|
import "./task.js";
|
|
8
|
-
import "./metrics.js";
|
|
9
9
|
import "./queue.js";
|
|
10
10
|
export {};
|
package/dist/services/queue.d.ts
CHANGED
|
@@ -3,8 +3,8 @@ import { QueueStatus } from "../interfaces/queueStatus.js";
|
|
|
3
3
|
import { QueueContext } from "../interfaces/queueContext.js";
|
|
4
4
|
import { QueueConnectionConfig } from "../interfaces/index.js";
|
|
5
5
|
import { RabbitMQProvider } from "../providers/rabbitmq/index.js";
|
|
6
|
-
import { HealthCheckResult, OnHealthCheck } from "@diia-inhouse/types";
|
|
7
6
|
import { MetricsService } from "@diia-inhouse/diia-metrics";
|
|
7
|
+
import { HealthCheckResult, OnHealthCheck } from "@diia-inhouse/types";
|
|
8
8
|
import Logger$1 from "@diia-inhouse/diia-logger";
|
|
9
9
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
10
10
|
|
package/dist/services/task.js
CHANGED
|
@@ -2,7 +2,7 @@ import { QueueTypes } from "../interfaces/messageBrokerServiceConfig.js";
|
|
|
2
2
|
import "../interfaces/index.js";
|
|
3
3
|
import constants_default from "../constants.js";
|
|
4
4
|
import Communicator from "./communicator.js";
|
|
5
|
-
import
|
|
5
|
+
import lodash from "lodash";
|
|
6
6
|
//#region src/services/task.ts
|
|
7
7
|
var Task = class extends Communicator {
|
|
8
8
|
serviceName;
|
|
@@ -18,8 +18,8 @@ var Task = class extends Communicator {
|
|
|
18
18
|
}
|
|
19
19
|
async onInit() {
|
|
20
20
|
const { queuesOptions, exchangesOptions } = await this.init();
|
|
21
|
-
const queuesOptionsMap =
|
|
22
|
-
const exchangesOptionsMap =
|
|
21
|
+
const queuesOptionsMap = lodash.keyBy(queuesOptions, "name");
|
|
22
|
+
const exchangesOptionsMap = lodash.keyBy(exchangesOptions, "name");
|
|
23
23
|
for (const task of this.taskList) {
|
|
24
24
|
const { name: taskName, isDelayed = false, queueNames = [] } = task;
|
|
25
25
|
if (queueNames.length === 0) {
|
|
@@ -69,8 +69,8 @@ var Task = class extends Communicator {
|
|
|
69
69
|
getUnicastListeners() {
|
|
70
70
|
const listeners = [];
|
|
71
71
|
const { queuesOptions, exchangesOptions } = this.queueProvider.getMessageBrokerServiceConfig();
|
|
72
|
-
const queuesOptionsMap =
|
|
73
|
-
const exchangesOptionsMap =
|
|
72
|
+
const queuesOptionsMap = lodash.keyBy(queuesOptions, "name");
|
|
73
|
+
const exchangesOptionsMap = lodash.keyBy(exchangesOptions, "name");
|
|
74
74
|
for (const task of this.taskList) {
|
|
75
75
|
const { queueNames = [], name: taskName, isDelayed = false } = task;
|
|
76
76
|
if (queueNames.length === 0) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@diia-inhouse/diia-queue",
|
|
3
|
-
"version": "14.2.
|
|
3
|
+
"version": "14.2.40",
|
|
4
4
|
"description": "Package provide queue functionality",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
6
6
|
"author": "diia-team",
|
|
@@ -38,9 +38,9 @@
|
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@diia-inhouse/configs": "7.2.2",
|
|
41
|
-
"@diia-inhouse/diia-logger": "4.7.
|
|
42
|
-
"@diia-inhouse/diia-metrics": "7.1.
|
|
43
|
-
"@diia-inhouse/env": "3.3.
|
|
41
|
+
"@diia-inhouse/diia-logger": "4.7.22",
|
|
42
|
+
"@diia-inhouse/diia-metrics": "7.1.149",
|
|
43
|
+
"@diia-inhouse/env": "3.3.89",
|
|
44
44
|
"@diia-inhouse/errors": "2.3.25",
|
|
45
45
|
"@diia-inhouse/oxc-config": "5.0.0",
|
|
46
46
|
"@diia-inhouse/test": "8.3.40",
|