@diia-inhouse/diia-queue 8.0.0 → 13.2.1
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/LICENCE.md +59 -59
- package/dist/constants.js +3 -0
- package/dist/constants.js.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/interfaces/index.js +6 -4
- package/dist/interfaces/index.js.map +1 -1
- package/dist/interfaces/messageBrokerServiceConfig.js +26 -0
- package/dist/interfaces/messageBrokerServiceConfig.js.map +1 -0
- package/dist/interfaces/metrics/index.js +14 -0
- package/dist/interfaces/metrics/index.js.map +1 -1
- package/dist/interfaces/providers/rabbitmq/amqpConnection.js +4 -1
- package/dist/interfaces/providers/rabbitmq/amqpConnection.js.map +1 -1
- package/dist/interfaces/providers/rabbitmq/amqpPublisher.js +1 -9
- package/dist/interfaces/providers/rabbitmq/amqpPublisher.js.map +1 -1
- package/dist/interfaces/providers/rabbitmq/index.js +41 -17
- package/dist/interfaces/providers/rabbitmq/index.js.map +1 -1
- package/dist/interfaces/queueStatus.js.map +1 -1
- package/dist/interfaces/{eventBus.js → services/eventMessageHandler.js} +1 -1
- package/dist/interfaces/services/eventMessageHandler.js.map +1 -0
- package/dist/metrics/index.js +1 -2
- package/dist/metrics/index.js.map +1 -1
- package/dist/providers/index.js +22 -0
- package/dist/providers/index.js.map +1 -0
- package/dist/providers/rabbitmq/amqpAsserter.js +417 -0
- package/dist/providers/rabbitmq/amqpAsserter.js.map +1 -0
- package/dist/providers/rabbitmq/amqpConnection.js +47 -25
- package/dist/providers/rabbitmq/amqpConnection.js.map +1 -1
- package/dist/providers/rabbitmq/amqpListener.js +167 -113
- package/dist/providers/rabbitmq/amqpListener.js.map +1 -1
- package/dist/providers/rabbitmq/amqpPublisher.js +145 -96
- package/dist/providers/rabbitmq/amqpPublisher.js.map +1 -1
- package/dist/providers/rabbitmq/index.js +104 -285
- package/dist/providers/rabbitmq/index.js.map +1 -1
- package/dist/services/communicator.js +187 -0
- package/dist/services/communicator.js.map +1 -0
- package/dist/services/eventBus.js +41 -46
- package/dist/services/eventBus.js.map +1 -1
- package/dist/services/eventCommunicator.js +125 -0
- package/dist/services/eventCommunicator.js.map +1 -0
- package/dist/services/eventMessageHandler.js +73 -89
- package/dist/services/eventMessageHandler.js.map +1 -1
- package/dist/services/externalCommunicator.js +10 -103
- package/dist/services/externalCommunicator.js.map +1 -1
- package/dist/services/externalEventBus.js +147 -55
- package/dist/services/externalEventBus.js.map +1 -1
- package/dist/services/index.js +1 -1
- package/dist/services/index.js.map +1 -1
- package/dist/services/metrics.js +49 -0
- package/dist/services/metrics.js.map +1 -0
- package/dist/services/optionsBuilder.js +59 -0
- package/dist/services/optionsBuilder.js.map +1 -0
- package/dist/services/queue.js +63 -26
- package/dist/services/queue.js.map +1 -1
- package/dist/services/scheduledTask.js +52 -48
- package/dist/services/scheduledTask.js.map +1 -1
- package/dist/services/task.js +149 -28
- package/dist/services/task.js.map +1 -1
- package/dist/types/constants.d.ts +3 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/interfaces/deps.d.ts +3 -2
- package/dist/types/interfaces/externalCommunicator.d.ts +5 -12
- package/dist/types/interfaces/index.d.ts +70 -20
- package/dist/types/interfaces/messageBrokerServiceConfig.d.ts +79 -0
- package/dist/types/interfaces/messageHandler.d.ts +1 -1
- package/dist/types/interfaces/metrics/index.d.ts +13 -0
- package/dist/types/interfaces/options.d.ts +29 -4
- package/dist/types/interfaces/providers/rabbitmq/amqpConnection.d.ts +3 -0
- package/dist/types/interfaces/providers/rabbitmq/amqpPublisher.d.ts +9 -17
- package/dist/types/interfaces/providers/rabbitmq/index.d.ts +71 -7
- package/dist/types/interfaces/queueConfig/configs.d.ts +19 -11
- package/dist/types/interfaces/queueStatus.d.ts +3 -1
- package/dist/types/interfaces/services/eventMessageHandler.d.ts +5 -0
- package/dist/types/metrics/index.d.ts +1 -2
- package/dist/types/providers/index.d.ts +5 -0
- package/dist/types/providers/rabbitmq/amqpAsserter.d.ts +49 -0
- package/dist/types/providers/rabbitmq/amqpConnection.d.ts +3 -7
- package/dist/types/providers/rabbitmq/amqpListener.d.ts +26 -11
- package/dist/types/providers/rabbitmq/amqpPublisher.d.ts +25 -16
- package/dist/types/providers/rabbitmq/index.d.ts +33 -40
- package/dist/types/services/communicator.d.ts +57 -0
- package/dist/types/services/eventBus.d.ts +15 -14
- package/dist/types/services/eventCommunicator.d.ts +15 -0
- package/dist/types/services/eventMessageHandler.d.ts +9 -11
- package/dist/types/services/externalCommunicator.d.ts +6 -19
- package/dist/types/services/externalEventBus.d.ts +28 -13
- package/dist/types/services/index.d.ts +1 -1
- package/dist/types/services/metrics.d.ts +11 -0
- package/dist/types/services/optionsBuilder.d.ts +10 -0
- package/dist/types/services/queue.d.ts +14 -9
- package/dist/types/services/scheduledTask.d.ts +22 -14
- package/dist/types/services/task.d.ts +21 -11
- package/dist/types/utils.d.ts +2 -2
- package/dist/utils.js +5 -2
- package/dist/utils.js.map +1 -1
- package/package.json +34 -41
- package/dist/interfaces/eventBus.js.map +0 -1
- package/dist/interfaces/providers/rabbitmq/amqpListener.js +0 -3
- package/dist/interfaces/providers/rabbitmq/amqpListener.js.map +0 -1
- package/dist/services/externalCommunicatorChannel.js +0 -31
- package/dist/services/externalCommunicatorChannel.js.map +0 -1
- package/dist/types/interfaces/eventBus.d.ts +0 -19
- package/dist/types/interfaces/providers/rabbitmq/amqpListener.d.ts +0 -7
- package/dist/types/services/externalCommunicatorChannel.d.ts +0 -11
|
@@ -1,23 +1,34 @@
|
|
|
1
1
|
import * as amqp from 'amqplib';
|
|
2
|
+
import { ErrorData } from '@diia-inhouse/errors/dist/types/interfaces';
|
|
2
3
|
import { AmqpConnection } from '../../../providers/rabbitmq/amqpConnection';
|
|
4
|
+
import { BaseQueueOptions } from '../../messageBrokerServiceConfig';
|
|
3
5
|
import { ListenerOptions } from '../../options';
|
|
4
|
-
import { EventName } from '../../queueConfig';
|
|
6
|
+
import { EventName, QueueConfigByQueueName, ServiceConfigByConfigType, TopicConfigByConfigType } from '../../queueConfig';
|
|
5
7
|
import { ConnectOptions, ConnectionStatus, ReconnectOptions, SocketOptions } from './amqpConnection';
|
|
6
|
-
export * from './amqpConnection';
|
|
7
|
-
export * from './amqpPublisher';
|
|
8
8
|
export interface RabbitMQConfigCustomParams {
|
|
9
9
|
responseRoutingKeyPrefix?: string;
|
|
10
10
|
}
|
|
11
|
+
export interface DeclareOptions {
|
|
12
|
+
assertQueues?: boolean;
|
|
13
|
+
assertExchanges?: boolean;
|
|
14
|
+
queuesOptions?: BaseQueueOptions;
|
|
15
|
+
}
|
|
11
16
|
export interface RabbitMQConfig {
|
|
12
17
|
connection: ConnectOptions;
|
|
13
18
|
socketOptions?: SocketOptions;
|
|
14
19
|
reconnectOptions?: ReconnectOptions;
|
|
15
20
|
custom?: RabbitMQConfigCustomParams;
|
|
16
|
-
assertExchanges?: boolean;
|
|
17
21
|
listenerOptions: ListenerOptions;
|
|
22
|
+
declareOptions?: DeclareOptions;
|
|
23
|
+
/**
|
|
24
|
+
* Whether to create consumer (listener) connections. When `false`, only publisher
|
|
25
|
+
* and asserter connections are established. Defaults to `true`.
|
|
26
|
+
*/
|
|
27
|
+
consumerEnabled?: boolean;
|
|
18
28
|
}
|
|
19
29
|
export declare enum ConnectionClientType {
|
|
20
30
|
Listener = "listener",
|
|
31
|
+
Asserter = "asserter",
|
|
21
32
|
Publisher = "publisher"
|
|
22
33
|
}
|
|
23
34
|
export type ConnectionList = {
|
|
@@ -30,21 +41,74 @@ export interface QueueMessageMetaData {
|
|
|
30
41
|
xid?: string;
|
|
31
42
|
responseRoutingKey?: string;
|
|
32
43
|
ignoreCache?: boolean;
|
|
44
|
+
registryApiVersion?: string;
|
|
45
|
+
}
|
|
46
|
+
export interface QueueMessageError {
|
|
47
|
+
data: ErrorData;
|
|
48
|
+
message: string;
|
|
49
|
+
http_code: number;
|
|
33
50
|
}
|
|
34
51
|
export interface QueueMessageData<T = any> {
|
|
35
52
|
event: EventName | string;
|
|
36
53
|
payload: T;
|
|
37
54
|
meta: QueueMessageMetaData;
|
|
38
55
|
}
|
|
56
|
+
export type MessageData = Pick<QueueMessageData, 'payload' | 'event'>;
|
|
57
|
+
export declare class Message<T = unknown> {
|
|
58
|
+
data: QueueMessageData<T>;
|
|
59
|
+
constructor(data: QueueMessageData<T>);
|
|
60
|
+
}
|
|
39
61
|
export type MessageProperties = amqp.MessageProperties;
|
|
40
62
|
export interface QueueMessage {
|
|
41
63
|
id?: unknown;
|
|
42
64
|
data: QueueMessageData;
|
|
43
65
|
properties: MessageProperties;
|
|
44
|
-
done: (data?:
|
|
45
|
-
reject: () => void;
|
|
66
|
+
done: (data?: QueueMessageData) => void;
|
|
67
|
+
reject: (nackOptions: NackOptions) => void;
|
|
46
68
|
}
|
|
47
69
|
export interface RabbitMQStatus {
|
|
48
|
-
listener
|
|
70
|
+
listener?: ConnectionStatus;
|
|
49
71
|
publisher: ConnectionStatus;
|
|
50
72
|
}
|
|
73
|
+
export interface ExportConfig {
|
|
74
|
+
queues: QueueConfigByQueueName;
|
|
75
|
+
rabbit: RabbitMQConfig;
|
|
76
|
+
topics: TopicConfigByConfigType;
|
|
77
|
+
service: ServiceConfigByConfigType;
|
|
78
|
+
portalEvents: EventName[];
|
|
79
|
+
}
|
|
80
|
+
export declare const Headers: {
|
|
81
|
+
readonly sentFrom: "sent-from";
|
|
82
|
+
readonly handledBy: "handled-by";
|
|
83
|
+
};
|
|
84
|
+
export declare class NackOptions {
|
|
85
|
+
/**
|
|
86
|
+
* If requeue is truthy, the server will try to put the message or messages back on the queue or queues from which they came.
|
|
87
|
+
* Defaults to true if not given, so if you want to make sure messages are dead-lettered or discarded, supply false here.
|
|
88
|
+
*/
|
|
89
|
+
readonly requeue: boolean;
|
|
90
|
+
/**
|
|
91
|
+
* If allUpTo is truthy, all outstanding messages prior to and including the given message are rejected. Defaults to false.
|
|
92
|
+
*/
|
|
93
|
+
readonly allUpTo: boolean;
|
|
94
|
+
constructor(
|
|
95
|
+
/**
|
|
96
|
+
* If requeue is truthy, the server will try to put the message or messages back on the queue or queues from which they came.
|
|
97
|
+
* Defaults to true if not given, so if you want to make sure messages are dead-lettered or discarded, supply false here.
|
|
98
|
+
*/
|
|
99
|
+
requeue?: boolean,
|
|
100
|
+
/**
|
|
101
|
+
* If allUpTo is truthy, all outstanding messages prior to and including the given message are rejected. Defaults to false.
|
|
102
|
+
*/
|
|
103
|
+
allUpTo?: boolean);
|
|
104
|
+
}
|
|
105
|
+
export declare const Arguments: {
|
|
106
|
+
readonly queueType: "x-queue-type";
|
|
107
|
+
/**
|
|
108
|
+
* @deprecated the RabbitMQ plugin that supports delayed messages is deprecated and should be removed in the future
|
|
109
|
+
*/
|
|
110
|
+
readonly delayedType: "x-delayed-type";
|
|
111
|
+
readonly deliveryLimit: "x-delivery-limit";
|
|
112
|
+
readonly deadLetterExchange: "x-dead-letter-exchange";
|
|
113
|
+
readonly deadLetterExchangeRoutingKey: "x-dead-letter-routing-key";
|
|
114
|
+
};
|
|
@@ -1,39 +1,47 @@
|
|
|
1
|
+
import { ExchangeName, MessageBrokerServicesConfig } from '../messageBrokerServiceConfig';
|
|
1
2
|
export type EventName = string;
|
|
2
3
|
export type QueueName = string;
|
|
3
|
-
export type Topic = string;
|
|
4
4
|
export declare enum QueueConfigType {
|
|
5
5
|
Internal = "internal",
|
|
6
6
|
External = "external"
|
|
7
7
|
}
|
|
8
8
|
export interface InternalServiceConfig {
|
|
9
9
|
subscribe?: QueueName[];
|
|
10
|
-
publish?:
|
|
10
|
+
publish?: ExchangeName[];
|
|
11
11
|
}
|
|
12
12
|
export interface ExternalServiceConfig {
|
|
13
|
-
|
|
13
|
+
/**
|
|
14
|
+
* add an event to this field only in cases when you don't need to await a response to an event;
|
|
15
|
+
* in other cases, use the *receiveDirect* mechanism
|
|
16
|
+
* */
|
|
17
|
+
publish?: EventName[];
|
|
14
18
|
subscribe: EventName[];
|
|
15
19
|
}
|
|
16
20
|
export type ServiceConfigByConfigType = InternalServiceConfig | ExternalServiceConfig;
|
|
17
21
|
export interface ServiceConfig {
|
|
18
|
-
|
|
19
|
-
|
|
22
|
+
/**
|
|
23
|
+
* @deprecated no need to set the internal service queues config, because it is used nowhere.
|
|
24
|
+
* it should be deleted from a service config
|
|
25
|
+
* */
|
|
26
|
+
[QueueConfigType.Internal]?: InternalServiceConfig;
|
|
27
|
+
[QueueConfigType.External]?: ExternalServiceConfig;
|
|
20
28
|
}
|
|
21
29
|
export type QueueConfigByQueueName = {
|
|
22
|
-
[k in QueueName]
|
|
23
|
-
topics:
|
|
30
|
+
[k in QueueName]: {
|
|
31
|
+
topics: ExchangeName[];
|
|
24
32
|
};
|
|
25
33
|
};
|
|
26
34
|
export type QueueConfig = Record<QueueConfigType.Internal, QueueConfigByQueueName>;
|
|
27
35
|
export type TopicConfigByConfigType = {
|
|
28
|
-
[k in
|
|
36
|
+
[k in ExchangeName]: {
|
|
29
37
|
events: EventName[];
|
|
30
38
|
};
|
|
31
39
|
};
|
|
32
40
|
export type TopicConfig = Record<QueueConfigType, TopicConfigByConfigType>;
|
|
33
41
|
export type ServiceRulesConfig = {
|
|
34
|
-
servicesConfig: ServiceConfig;
|
|
35
42
|
topicsConfig: TopicConfig;
|
|
36
43
|
queuesConfig: QueueConfig;
|
|
37
|
-
portalEvents
|
|
38
|
-
|
|
44
|
+
portalEvents?: EventName[];
|
|
45
|
+
servicesConfig?: ServiceConfig;
|
|
46
|
+
messageBrokerServices?: MessageBrokerServicesConfig;
|
|
39
47
|
};
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import { MessageBrokerServiceType } from './messageBrokerServiceConfig';
|
|
1
2
|
import { RabbitMQStatus } from './providers/rabbitmq';
|
|
2
3
|
export declare enum QueueConnectionType {
|
|
3
4
|
Internal = "internal",
|
|
4
5
|
External = "external"
|
|
5
6
|
}
|
|
6
|
-
export type
|
|
7
|
+
export type MessageBrokerServicesStatus = Partial<Record<MessageBrokerServiceType, RabbitMQStatus>>;
|
|
8
|
+
export type QueueStatusByType = Partial<Record<QueueConnectionType, MessageBrokerServicesStatus>>;
|
|
7
9
|
export type QueueStatus = {
|
|
8
10
|
rabbit: QueueStatusByType;
|
|
9
11
|
};
|
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
import { Counter } from '@diia-inhouse/diia-metrics';
|
|
2
|
-
import { TotalListenerChannelErrorsLabelsMap
|
|
2
|
+
import { TotalListenerChannelErrorsLabelsMap } from '../interfaces/metrics';
|
|
3
3
|
export declare const totalListenerChannelErrorsMetric: Counter<TotalListenerChannelErrorsLabelsMap>;
|
|
4
|
-
export declare const totalMessageHandlerErrorsMetrics: Counter<TotalMessageHandlerErrorsLabelsMap>;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Replies } from 'amqplib';
|
|
2
|
+
import { Logger } from '@diia-inhouse/types';
|
|
3
|
+
import { DeclareOptions } from '../../interfaces';
|
|
4
|
+
import { BindOptions, ExchangeName, ExchangeOptions, QueueOptions, UnbindOptions } from '../../interfaces/messageBrokerServiceConfig';
|
|
5
|
+
import { QueueName } from '../../interfaces/queueConfig';
|
|
6
|
+
import { AmqpConnection } from './amqpConnection';
|
|
7
|
+
export declare class AmqpAsserter {
|
|
8
|
+
private readonly connection;
|
|
9
|
+
private readonly logger;
|
|
10
|
+
private readonly declareOptions;
|
|
11
|
+
static PrefixAlternate: string;
|
|
12
|
+
private readonly defaultExchangeType;
|
|
13
|
+
private readonly defaultQueueOptions;
|
|
14
|
+
private readonly defaultExchangeOptions;
|
|
15
|
+
private readonly defaultDeclareOptions;
|
|
16
|
+
private channel?;
|
|
17
|
+
private readonly channelName;
|
|
18
|
+
constructor(connection: AmqpConnection, logger: Logger, declareOptions?: DeclareOptions);
|
|
19
|
+
init(exchangesOptions?: ExchangeOptions[], queuesOptions?: QueueOptions[]): Promise<void>;
|
|
20
|
+
declareQueuesByJSON(declarationConfigPath: string): Promise<void>;
|
|
21
|
+
declareQueues(queuesOptions?: QueueOptions[], exchangesOptions?: ExchangeOptions[]): Promise<void>;
|
|
22
|
+
redeclareQueue(queueOptions: QueueOptions, exchangesOptions: ExchangeOptions[]): Promise<boolean>;
|
|
23
|
+
transferMessageBetweenQueues(sourceQueueName: QueueName, destinationQueueName: QueueName): Promise<void>;
|
|
24
|
+
deleteExchanges(exchangesOptions: ExchangeOptions[]): Promise<Record<ExchangeName, Replies.Empty | undefined>>;
|
|
25
|
+
deleteExchange(exchangeName: string): Promise<Replies.Empty | undefined>;
|
|
26
|
+
deleteQueues(queueNames: QueueName[]): Promise<Record<QueueName, Replies.DeleteQueue | undefined>>;
|
|
27
|
+
deleteQueue(queueName: QueueName): Promise<Replies.DeleteQueue | undefined>;
|
|
28
|
+
assertQueues(queueOptions: QueueOptions[]): Promise<Record<QueueName, Replies.AssertQueue | undefined>>;
|
|
29
|
+
assertQueue(queueOptions: QueueOptions): Promise<Replies.AssertQueue | undefined>;
|
|
30
|
+
assertExchanges(exchangeOptions: ExchangeOptions[]): Promise<Record<QueueName, Replies.AssertExchange | undefined>>;
|
|
31
|
+
assertExchange(exchangeOptions: ExchangeOptions): Promise<Replies.AssertExchange | undefined>;
|
|
32
|
+
unbindQueueFromExchanges(queueOptions: QueueOptions): Promise<undefined>;
|
|
33
|
+
bindQueueToExchange(queueName: QueueName, bindOptions: BindOptions): Promise<Replies.Empty | undefined>;
|
|
34
|
+
bindExchangeToExchanges(exchangeName: ExchangeName, bindTo: BindOptions[]): Promise<undefined>;
|
|
35
|
+
bindExchangeToExchange(exchangeName: ExchangeName, bindOptions: BindOptions): Promise<Replies.Empty | undefined>;
|
|
36
|
+
unbindQueueFromExchange(queueName: QueueName, unbindOptions: UnbindOptions): Promise<Replies.Empty | undefined>;
|
|
37
|
+
disconnect(): Promise<void>;
|
|
38
|
+
private initChannel;
|
|
39
|
+
private readConfig;
|
|
40
|
+
private assertTemporaryQueue;
|
|
41
|
+
private assertAlternateExchanges;
|
|
42
|
+
private assertAlternateQueue;
|
|
43
|
+
private prepareRedeclareQueueOptions;
|
|
44
|
+
private prepareTemporaryQueueOptions;
|
|
45
|
+
private prepareAlternateExchangesOptions;
|
|
46
|
+
private prepareAlternateExchangeOptions;
|
|
47
|
+
private prepareAlternateQueueOptions;
|
|
48
|
+
private prepareAlternateBindToQueueOption;
|
|
49
|
+
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
1
|
import { EventEmitter } from 'node:events';
|
|
3
2
|
import { Channel, Options } from 'amqplib';
|
|
4
3
|
import { Logger } from '@diia-inhouse/types';
|
|
@@ -10,14 +9,11 @@ export declare class AmqpConnection extends EventEmitter {
|
|
|
10
9
|
private readonly socketOptions;
|
|
11
10
|
private reconnectEnabled;
|
|
12
11
|
private reconnectTimeout;
|
|
13
|
-
private connection
|
|
12
|
+
private connection?;
|
|
14
13
|
private connectionStatus;
|
|
15
|
-
constructor(connectOptions: Options.Connect, logger: Logger, reconnectOptions?: ReconnectOptions, socketOptions?: SocketOptions);
|
|
14
|
+
constructor(connectOptions: Options.Connect, logger: Logger, reconnectOptions?: ReconnectOptions | undefined, socketOptions?: SocketOptions);
|
|
16
15
|
connect(): Promise<void>;
|
|
17
|
-
|
|
18
|
-
* Create new channel
|
|
19
|
-
*/
|
|
20
|
-
createChannel(queueName: string): Promise<Channel>;
|
|
16
|
+
createChannel(queueName?: string): Promise<Channel>;
|
|
21
17
|
reconnect(): Promise<void>;
|
|
22
18
|
closeConnection(): Promise<void>;
|
|
23
19
|
getStatus(): ConnectionStatus;
|
|
@@ -1,27 +1,42 @@
|
|
|
1
|
-
import { Options, Replies } from 'amqplib';
|
|
2
1
|
import { Logger } from '@diia-inhouse/types';
|
|
3
|
-
import {
|
|
2
|
+
import { MessageHandler, QueueOptions } from '../../interfaces';
|
|
4
3
|
import { ConnectionStatus } from '../../interfaces/providers/rabbitmq/amqpConnection';
|
|
5
|
-
import {
|
|
4
|
+
import { QueueName } from '../../interfaces/queueConfig';
|
|
5
|
+
import RabbitMQMetricsService from '../../services/metrics';
|
|
6
6
|
import { AmqpConnection } from './amqpConnection';
|
|
7
7
|
export declare class AmqpListener {
|
|
8
8
|
private connection;
|
|
9
9
|
private readonly logger;
|
|
10
|
-
private readonly
|
|
11
|
-
private
|
|
12
|
-
private
|
|
13
|
-
|
|
10
|
+
private readonly rabbitMQMetrics;
|
|
11
|
+
private readonly queuesOptions;
|
|
12
|
+
private readonly systemServiceName;
|
|
13
|
+
private readonly infiniteRecreateChannelTriesCount;
|
|
14
|
+
private readonly defaultRecreateChannelOptions;
|
|
15
|
+
private readonly defaultPrefetchCount;
|
|
16
|
+
private queuesChannelsMap;
|
|
17
|
+
private queueRecreateChannelTriesMap;
|
|
18
|
+
private readonly defaultNackOptions;
|
|
19
|
+
private queuesCallbacksMap;
|
|
20
|
+
private queueConsumerOptionsMap;
|
|
21
|
+
private queueConsumerTagsMap;
|
|
22
|
+
private readonly nullMessage;
|
|
23
|
+
constructor(connection: AmqpConnection, logger: Logger, rabbitMQMetrics: RabbitMQMetricsService, queuesOptions: QueueOptions[] | undefined, systemServiceName: string);
|
|
14
24
|
init(): Promise<void>;
|
|
15
|
-
|
|
16
|
-
|
|
25
|
+
cancelQueue(queueName: QueueName): Promise<void>;
|
|
26
|
+
listenQueue(queueName: QueueName, callback: MessageHandler): Promise<void | never>;
|
|
17
27
|
getStatus(): ConnectionStatus;
|
|
18
28
|
private ackMsg;
|
|
19
29
|
private nackMsg;
|
|
20
30
|
private createChannelAndListenQueue;
|
|
21
31
|
private saveQueueCallback;
|
|
22
32
|
private getQueueCallback;
|
|
23
|
-
private getChannel;
|
|
24
|
-
private getQueueOptions;
|
|
25
33
|
private saveChannel;
|
|
26
34
|
private onMessageCallback;
|
|
35
|
+
private handleChannelError;
|
|
36
|
+
private parseMessage;
|
|
37
|
+
private prepareResponse;
|
|
38
|
+
private finishResponseProcessing;
|
|
39
|
+
private getConsumerOptions;
|
|
40
|
+
private getQueueChannel;
|
|
41
|
+
private saveConsumerTag;
|
|
27
42
|
}
|
|
@@ -1,25 +1,34 @@
|
|
|
1
|
-
import { Options, Replies } from 'amqplib';
|
|
2
1
|
import { Logger } from '@diia-inhouse/types';
|
|
2
|
+
import { ExchangeName } from '../../interfaces/messageBrokerServiceConfig';
|
|
3
|
+
import { PublisherOptions } from '../../interfaces/options';
|
|
4
|
+
import { QueueMessageData } from '../../interfaces/providers/rabbitmq';
|
|
3
5
|
import { ConnectionStatus } from '../../interfaces/providers/rabbitmq/amqpConnection';
|
|
4
|
-
import {
|
|
6
|
+
import { MessageHeaders, PublishingResult } from '../../interfaces/providers/rabbitmq/amqpPublisher';
|
|
7
|
+
import RabbitMQMetricsService from '../../services/metrics';
|
|
5
8
|
import { AmqpConnection } from './amqpConnection';
|
|
6
9
|
export declare class AmqpPublisher {
|
|
7
10
|
private readonly connection;
|
|
8
11
|
private readonly logger;
|
|
9
|
-
private readonly
|
|
10
|
-
readonly
|
|
11
|
-
private
|
|
12
|
-
private
|
|
13
|
-
private
|
|
14
|
-
|
|
12
|
+
private readonly rabbitMQMetrics;
|
|
13
|
+
private readonly systemServiceName;
|
|
14
|
+
private readonly defaultPublishOptions;
|
|
15
|
+
private rpcChannel?;
|
|
16
|
+
private regularChannel?;
|
|
17
|
+
private readonly replyToQueueName;
|
|
18
|
+
private eventEmitter?;
|
|
19
|
+
private readonly directResponseTimeout;
|
|
20
|
+
constructor(connection: AmqpConnection, logger: Logger, rabbitMQMetrics: RabbitMQMetricsService, systemServiceName: string, options?: PublisherOptions);
|
|
15
21
|
init(): Promise<void>;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
publishToExchangeDirect<T>(params: PublishToExchangeParams): Promise<T>;
|
|
19
|
-
private static prepareQueueMessageData;
|
|
20
|
-
private publishDirect;
|
|
21
|
-
private publish;
|
|
22
|
-
private static defaultPublishOptions;
|
|
23
|
-
checkExchange(exchangeName: string, exchangeType?: ExchangeType, options?: Options.AssertExchange): Promise<Replies.AssertExchange>;
|
|
22
|
+
publishToExchange(exchangeName: ExchangeName, message: QueueMessageData, headers: MessageHeaders, routingKey?: string): Promise<PublishingResult>;
|
|
23
|
+
publishToExchangeDirect<T>(exchangeName: ExchangeName, message: QueueMessageData, headers: MessageHeaders, routingKey?: string, responseTimeoutMs?: number): Promise<T>;
|
|
24
24
|
getStatus(): ConnectionStatus;
|
|
25
|
+
private createRegularChannel;
|
|
26
|
+
private createRpcChannel;
|
|
27
|
+
private listenReplyToQueue;
|
|
28
|
+
private publishMessage;
|
|
29
|
+
private publishRequest;
|
|
30
|
+
private publish;
|
|
31
|
+
private getPublishOptions;
|
|
32
|
+
private receiveDirectResponse;
|
|
33
|
+
private collectMetrics;
|
|
25
34
|
}
|
|
@@ -1,59 +1,52 @@
|
|
|
1
|
-
|
|
2
|
-
/// <reference types="node" />
|
|
3
|
-
import { type AsyncLocalStorage } from 'node:async_hooks';
|
|
1
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
4
2
|
import { EventEmitter } from 'node:events';
|
|
3
|
+
import { MetricsService } from '@diia-inhouse/diia-metrics';
|
|
5
4
|
import { Logger } from '@diia-inhouse/types';
|
|
5
|
+
import { PublishingResult } from '../../interfaces';
|
|
6
|
+
import { MessageBrokerServiceConfig, QueueOptions } from '../../interfaces/messageBrokerServiceConfig';
|
|
6
7
|
import { MessageHandler } from '../../interfaces/messageHandler';
|
|
7
|
-
import {
|
|
8
|
-
import { RabbitMQConfig, RabbitMQStatus } from '../../interfaces/providers/rabbitmq';
|
|
9
|
-
import {
|
|
10
|
-
import { EventName, QueueConfigByQueueName, QueueConfigType, QueueName, ServiceConfigByConfigType, Topic, TopicConfigByConfigType } from '../../interfaces/queueConfig';
|
|
8
|
+
import { PublishDirectOptions, PublishOptions } from '../../interfaces/options';
|
|
9
|
+
import { ConnectionClientType, ExportConfig, QueueMessageData, RabbitMQConfig, RabbitMQStatus } from '../../interfaces/providers/rabbitmq';
|
|
10
|
+
import { EventName, QueueConfigByQueueName, QueueName, ServiceConfigByConfigType, TopicConfigByConfigType } from '../../interfaces/queueConfig';
|
|
11
11
|
import { QueueContext } from '../../interfaces/queueContext';
|
|
12
|
+
import { AmqpAsserter } from './amqpAsserter';
|
|
13
|
+
import { AmqpConnection } from './amqpConnection';
|
|
14
|
+
import { AmqpListener } from './amqpListener';
|
|
15
|
+
import { AmqpPublisher } from './amqpPublisher';
|
|
12
16
|
export declare class RabbitMQProvider extends EventEmitter {
|
|
13
|
-
private readonly
|
|
17
|
+
private readonly systemServiceName;
|
|
14
18
|
private readonly rabbitmqConfig;
|
|
15
19
|
private readonly serviceConfig;
|
|
16
20
|
private readonly topicsConfig;
|
|
17
21
|
private readonly portalEvents;
|
|
18
|
-
private readonly internalEvents;
|
|
19
|
-
private readonly type;
|
|
20
22
|
private readonly logger;
|
|
23
|
+
private readonly metrics;
|
|
21
24
|
private readonly asyncLocalStorage?;
|
|
22
25
|
private readonly queuesConfig?;
|
|
26
|
+
private readonly messageBrokerServiceConfig?;
|
|
23
27
|
private initializingLock?;
|
|
24
|
-
private listener
|
|
25
|
-
private publisher
|
|
28
|
+
private listener?;
|
|
29
|
+
private publisher?;
|
|
30
|
+
private asserter?;
|
|
26
31
|
private connectionList;
|
|
27
|
-
private readonly
|
|
28
|
-
private readonly
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
subscribe(subscriptionName: QueueName, messageHandler: MessageHandler, options?: SubscribeOptions): Promise<boolean>;
|
|
38
|
-
publish(eventName: EventName, message: MessagePayload, options?: PublishInternalEventOptions): Promise<boolean>;
|
|
39
|
-
subscribeTask(queueName: string, messageHandler: MessageHandler, options?: SubscribeOptions): Promise<boolean>;
|
|
40
|
-
publishTask(queueName: string, message: MessagePayload, delay?: number): Promise<boolean>;
|
|
41
|
-
subscribeExternal(messageHandler: MessageHandler, options?: SubscribeOptions): Promise<boolean>;
|
|
42
|
-
publishExternalDirect<T>(eventName: EventName, message: MessagePayload, topic?: Topic, options?: PublishDirectOptions): Promise<T>;
|
|
43
|
-
publishExternal(eventName: EventName, message: MessagePayload, options?: PublishExternalEventOptions): Promise<boolean>;
|
|
32
|
+
private readonly publisherIsNotInitializedErrorMsg;
|
|
33
|
+
private readonly rabbitMQMetricsService;
|
|
34
|
+
constructor(systemServiceName: string, rabbitmqConfig: RabbitMQConfig, serviceConfig: ServiceConfigByConfigType, topicsConfig: TopicConfigByConfigType, portalEvents: EventName[], logger: Logger, metrics: MetricsService, asyncLocalStorage?: AsyncLocalStorage<QueueContext> | undefined, queuesConfig?: QueueConfigByQueueName | undefined, messageBrokerServiceConfig?: MessageBrokerServiceConfig | undefined);
|
|
35
|
+
getConfig(): ExportConfig;
|
|
36
|
+
getMessageBrokerServiceConfig(): MessageBrokerServiceConfig;
|
|
37
|
+
init(config?: MessageBrokerServiceConfig): Promise<void>;
|
|
38
|
+
subscribe(queueName: QueueName, messageHandler: MessageHandler): Promise<boolean>;
|
|
39
|
+
unsubscribe(queueName: QueueName): Promise<void>;
|
|
40
|
+
publish(message: QueueMessageData, exchangeName: string, routingKey?: string, options?: PublishOptions): Promise<PublishingResult>;
|
|
41
|
+
publishExternalDirect<T>(message: QueueMessageData, exchangeName: string, routingKey?: string, options?: PublishDirectOptions): Promise<T>;
|
|
44
42
|
getStatus(): RabbitMQStatus;
|
|
45
|
-
|
|
46
|
-
|
|
43
|
+
makeAMQPConnection(client: ConnectionClientType): Promise<AmqpConnection>;
|
|
44
|
+
makeAMQPListener(queuesOptions: QueueOptions[]): Promise<AmqpListener>;
|
|
45
|
+
makeAMQPAsserter(): Promise<AmqpAsserter>;
|
|
46
|
+
makeAMQPPublisher(): Promise<AmqpPublisher>;
|
|
47
47
|
private setListener;
|
|
48
|
+
private setAsserter;
|
|
48
49
|
private setPublisher;
|
|
49
50
|
private getConnection;
|
|
50
|
-
private
|
|
51
|
-
private bindQueueToExternalExchange;
|
|
52
|
-
private makeQueueName;
|
|
53
|
-
private makeExternalResQueueName;
|
|
54
|
-
private makeExternalReqQueueName;
|
|
55
|
-
private prepareExternalTopicName;
|
|
56
|
-
private prepareExternalReqRoutingKey;
|
|
57
|
-
private prepareExternalResRoutingKey;
|
|
58
|
-
private prepareExternalQueuePrefix;
|
|
51
|
+
private preparePublisherHeaders;
|
|
59
52
|
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import Logger from '@diia-inhouse/diia-logger';
|
|
2
|
+
import { ExchangeName, ExchangeOptions, Message, MessageBrokerServiceConfig, MessageBrokerServiceEventsListener, MessageData, MessageHandler, MessagePayload, PublishOptions, PublishingResult, QueueMessageData, QueueMessageMetaData } from '../interfaces';
|
|
3
|
+
import { EventName, QueueName } from '../interfaces/queueConfig';
|
|
4
|
+
import { RabbitMQProvider } from '../providers/rabbitmq';
|
|
5
|
+
import OptionsBuilder from './optionsBuilder';
|
|
6
|
+
export default abstract class Communicator {
|
|
7
|
+
protected readonly logger: Logger;
|
|
8
|
+
protected readonly queueProvider: RabbitMQProvider;
|
|
9
|
+
protected readonly hostName: string;
|
|
10
|
+
protected readonly systemServiceName: string;
|
|
11
|
+
protected readonly optionsBuilder: OptionsBuilder;
|
|
12
|
+
protected eventNameToExchangeNameMap: Map<EventName, ExchangeName>;
|
|
13
|
+
private queueBindToMap;
|
|
14
|
+
private exchangesMap;
|
|
15
|
+
private serviceConfig;
|
|
16
|
+
protected constructor(logger: Logger, queueProvider: RabbitMQProvider, hostName: string, systemServiceName: string);
|
|
17
|
+
onInit(): Promise<void>;
|
|
18
|
+
onDestroy(): Promise<void>;
|
|
19
|
+
subscribeToQueues(listeners: MessageBrokerServiceEventsListener[]): Promise<void>;
|
|
20
|
+
subscribe(queueName: QueueName, messageHandler: MessageHandler): Promise<boolean>;
|
|
21
|
+
unsubscribeFromQueues(queueNames: string[]): Promise<void>;
|
|
22
|
+
unsubscribe(queueName: QueueName): Promise<void>;
|
|
23
|
+
publishToQueue(queueName: QueueName, messageData: MessageData, options?: PublishOptions): Promise<PublishingResult>;
|
|
24
|
+
publishToExchange(exchangeName: ExchangeName, routingKey: string, messageData: MessageData | Message, options?: PublishOptions): Promise<PublishingResult>;
|
|
25
|
+
publishEventToExchange(eventName: EventName, payload: MessagePayload | Message, options?: PublishOptions): Promise<PublishingResult>;
|
|
26
|
+
getPublishQueueMessageData(eventName: EventName, message: MessagePayload, partialMeta?: Partial<QueueMessageMetaData>): QueueMessageData;
|
|
27
|
+
protected init(): Promise<MessageBrokerServiceConfig>;
|
|
28
|
+
private buildExchangesMap;
|
|
29
|
+
private buildEventNameToExchangeNameMap;
|
|
30
|
+
private getServiceConfig;
|
|
31
|
+
private unifyServiceConfig;
|
|
32
|
+
private enrichQueueConsumerOptions;
|
|
33
|
+
/**
|
|
34
|
+
* Gets global exchanges options.
|
|
35
|
+
* This method must be overridden by subclasses to provide a more specific implementation.
|
|
36
|
+
* @virtual
|
|
37
|
+
*/
|
|
38
|
+
protected abstract getProducerExchangesOptions(): ExchangeOptions[];
|
|
39
|
+
/**
|
|
40
|
+
* Gets unicast event listeners.
|
|
41
|
+
* This method must be overridden by subclasses to provide a more specific implementation.
|
|
42
|
+
* @virtual
|
|
43
|
+
*/
|
|
44
|
+
protected abstract getUnicastListeners(): MessageBrokerServiceEventsListener[];
|
|
45
|
+
/**
|
|
46
|
+
* Gets multicast event listeners.
|
|
47
|
+
* This method must be overridden by subclasses to provide a more specific implementation.
|
|
48
|
+
* @virtual
|
|
49
|
+
*/
|
|
50
|
+
protected abstract getMulticastListeners(): MessageBrokerServiceEventsListener[];
|
|
51
|
+
/**
|
|
52
|
+
* Gets an exchange name related to a service.
|
|
53
|
+
* This method must be overridden by subclasses to provide a more specific implementation.
|
|
54
|
+
* @virtual
|
|
55
|
+
*/
|
|
56
|
+
protected abstract getExchangeNameWithSuffix(exchangeName: ExchangeName): string;
|
|
57
|
+
}
|
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import Logger from '@diia-inhouse/diia-logger';
|
|
2
|
+
import { OnInit } from '@diia-inhouse/types';
|
|
3
|
+
import { EventBusListener, EventBusQueue, ExchangeName, MessageBrokerServiceEventsListener, PublishOptions, PublishingResult } from '../interfaces';
|
|
4
|
+
import { ExchangeOptions } from '../interfaces/messageBrokerServiceConfig';
|
|
5
5
|
import { MessagePayload } from '../interfaces/providers/rabbitmq/amqpPublisher';
|
|
6
|
-
import { QueueName } from '../interfaces/queueConfig';
|
|
6
|
+
import { EventName, QueueName } from '../interfaces/queueConfig';
|
|
7
7
|
import { RabbitMQProvider } from '../providers/rabbitmq';
|
|
8
|
+
import Communicator from './communicator';
|
|
8
9
|
import { EventMessageHandler } from './eventMessageHandler';
|
|
9
|
-
export declare class EventBus implements EventBusQueue, OnInit {
|
|
10
|
-
private readonly queueProvider;
|
|
10
|
+
export declare class EventBus extends Communicator implements EventBusQueue, OnInit {
|
|
11
11
|
private readonly eventListenerList;
|
|
12
|
-
private readonly
|
|
13
|
-
private readonly
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
12
|
+
private readonly queueName?;
|
|
13
|
+
private readonly eventCommunicator;
|
|
14
|
+
constructor(queueProvider: RabbitMQProvider, eventListenerList: EventBusListener[], eventMessageHandler: EventMessageHandler, logger: Logger, hostName: string, systemServiceName: string, queueName?: QueueName | undefined);
|
|
15
|
+
publish(eventName: EventName, payload: MessagePayload, options?: PublishOptions): Promise<PublishingResult>;
|
|
16
|
+
protected getExchangeNameWithSuffix(exchangeName: ExchangeName): string;
|
|
17
|
+
protected getUnicastListeners(): MessageBrokerServiceEventsListener[];
|
|
18
|
+
protected getProducerExchangesOptions(): ExchangeOptions[];
|
|
19
|
+
protected getMulticastListeners(): MessageBrokerServiceEventsListener[];
|
|
19
20
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import Logger from '@diia-inhouse/diia-logger';
|
|
2
|
+
import { EventBusListener, EventName, ExchangeOptions, MessageBrokerServiceEventsListener, QueueName, QueueOptions } from '../interfaces';
|
|
3
|
+
import { RabbitMQProvider } from '../providers';
|
|
4
|
+
import { EventMessageHandler } from './eventMessageHandler';
|
|
5
|
+
export declare class EventCommunicator {
|
|
6
|
+
private readonly logger;
|
|
7
|
+
private readonly queueProvider;
|
|
8
|
+
private readonly eventMessageHandler;
|
|
9
|
+
protected readonly listenerList: EventBusListener[];
|
|
10
|
+
constructor(logger: Logger, queueProvider: RabbitMQProvider, eventMessageHandler: EventMessageHandler, listenerList?: EventBusListener[]);
|
|
11
|
+
getMulticastListeners(queuesOptions: QueueOptions[], exchangesOptions: ExchangeOptions[], eventQueueMap?: Map<EventName, QueueName>): MessageBrokerServiceEventsListener[];
|
|
12
|
+
getUnicastListeners(): MessageBrokerServiceEventsListener[];
|
|
13
|
+
private defineConsumerExchangesOptions;
|
|
14
|
+
private defineEventNamesByQueueName;
|
|
15
|
+
}
|
|
@@ -1,21 +1,19 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
1
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import { EventBusListener, QueueContext, QueueMessage, TaskListener } from '../interfaces';
|
|
6
|
-
import { EventListeners } from '../interfaces/externalCommunicator';
|
|
2
|
+
import Logger from '@diia-inhouse/diia-logger';
|
|
3
|
+
import { EventBusListener, EventListeners, QueueContext, QueueMessage, TaskListener } from '../interfaces';
|
|
7
4
|
import { EventMessageValidator } from './eventMessageValidator';
|
|
8
|
-
import { ExternalCommunicatorChannel } from './externalCommunicatorChannel';
|
|
9
5
|
export declare class EventMessageHandler {
|
|
10
6
|
private readonly eventMessageValidator;
|
|
11
|
-
private readonly externalChannel;
|
|
12
|
-
private readonly pubsub;
|
|
13
7
|
private readonly asyncLocalStorage;
|
|
14
8
|
private readonly logger;
|
|
15
|
-
|
|
9
|
+
private readonly noRequeueNackOptions;
|
|
10
|
+
constructor(eventMessageValidator: EventMessageValidator, asyncLocalStorage: AsyncLocalStorage<QueueContext>, logger: Logger);
|
|
16
11
|
eventListenersMessageHandler(this: this, eventListeners: EventListeners, message: QueueMessage | null): Promise<void>;
|
|
17
12
|
eventListenerMessageHandler(listener: EventBusListener | TaskListener | undefined, message: QueueMessage): Promise<void>;
|
|
18
|
-
private
|
|
19
|
-
private
|
|
13
|
+
private prepareAsyncContext;
|
|
14
|
+
private handleMessage;
|
|
15
|
+
private validateData;
|
|
16
|
+
private directReplyDone;
|
|
20
17
|
private getServiceCode;
|
|
18
|
+
private prepareQueueMessageError;
|
|
21
19
|
}
|