@candlerip/shared 0.0.90 → 0.0.93
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/common/request/api/api-route/config.js +4 -0
- package/message-broker/message-broker/index.d.ts +1 -1
- package/message-broker/message-broker/index.js +1 -1
- package/message-broker/message-broker/workers/base/index.d.ts +2 -0
- package/message-broker/message-broker/{singletons → workers}/base/index.js +6 -16
- package/message-broker/message-broker/workers/base/type.d.ts +10 -0
- package/message-broker/message-broker/workers/index.d.ts +2 -0
- package/message-broker/message-broker/{singletons → workers}/index.js +4 -5
- package/message-broker/message-broker/{singletons → workers}/type.d.ts +4 -0
- package/message-broker/message-broker-queue-name/domains.d.ts +1 -1
- package/package.json +1 -1
- package/message-broker/message-broker/singletons/base/index.d.ts +0 -12
- package/message-broker/message-broker/singletons/base/type.d.ts +0 -8
- package/message-broker/message-broker/singletons/index.d.ts +0 -6
- /package/message-broker/message-broker/{singletons → workers}/base/type.js +0 -0
- /package/message-broker/message-broker/{singletons → workers}/type.js +0 -0
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export * from './domains.js';
|
|
2
|
-
export * from './
|
|
2
|
+
export * from './workers/index.js';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export * from './domains.js';
|
|
2
|
-
export * from './
|
|
2
|
+
export * from './workers/index.js';
|
|
@@ -1,21 +1,20 @@
|
|
|
1
1
|
import amqp from 'amqplib';
|
|
2
2
|
import { CustomErrorWorker } from '../../../../common/index.js';
|
|
3
|
-
export const
|
|
3
|
+
export const BaseMessageBrokerWorker = (url) => {
|
|
4
4
|
let _channel;
|
|
5
5
|
let _connection;
|
|
6
|
-
|
|
7
|
-
const errorWorker = CustomErrorWorker();
|
|
6
|
+
const errorWorker = CustomErrorWorker({ message: 'MessageBroker initializing...' });
|
|
8
7
|
const _handleError = (err) => {
|
|
9
8
|
errorWorker.addCustomErrorMessage('Error connect RabbitMQ');
|
|
10
9
|
errorWorker.addCustomErrorInfo({ err });
|
|
11
10
|
setTimeout(() => _connect(), 5000);
|
|
12
11
|
};
|
|
13
12
|
const _connect = async () => {
|
|
14
|
-
if (!
|
|
13
|
+
if (!url) {
|
|
15
14
|
return;
|
|
16
15
|
}
|
|
17
16
|
try {
|
|
18
|
-
_connection = await amqp.connect(
|
|
17
|
+
_connection = await amqp.connect(url);
|
|
19
18
|
_connection.on('error', (err) => {
|
|
20
19
|
_handleError(err);
|
|
21
20
|
});
|
|
@@ -37,18 +36,9 @@ export const BaseMessageBrokerSingleton = (() => {
|
|
|
37
36
|
data: _channel,
|
|
38
37
|
};
|
|
39
38
|
};
|
|
40
|
-
|
|
41
|
-
const error = errorWorker.getCustomError();
|
|
42
|
-
if (error) {
|
|
43
|
-
return error;
|
|
44
|
-
}
|
|
45
|
-
errorWorker.addCustomErrorMessage('MessageBroker initializing...');
|
|
46
|
-
_url = url;
|
|
47
|
-
_connect();
|
|
48
|
-
};
|
|
39
|
+
_connect();
|
|
49
40
|
return {
|
|
50
41
|
errorWorker,
|
|
51
42
|
getChannel,
|
|
52
|
-
init,
|
|
53
43
|
};
|
|
54
|
-
}
|
|
44
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import amqp from 'amqplib';
|
|
2
|
+
import { TCustomError } from '../../../../common/index.js';
|
|
3
|
+
import { TCustomErrorWorker } from '../../../../common/custom-error/workers/type.js';
|
|
4
|
+
export type TBaseMessageBrokerWorker = (url: string) => {
|
|
5
|
+
errorWorker: ReturnType<TCustomErrorWorker>;
|
|
6
|
+
getChannel: GetChannel;
|
|
7
|
+
};
|
|
8
|
+
export type _Connect = () => Promise<void>;
|
|
9
|
+
export type _HandleError = (err: unknown) => void;
|
|
10
|
+
export type GetChannel = () => TCustomError<amqp.Channel>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { composeCustomError, consoleCustomError, stringify } from '../../../common/index.js';
|
|
2
|
-
import {
|
|
3
|
-
export const
|
|
4
|
-
const { errorWorker, getChannel
|
|
2
|
+
import { BaseMessageBrokerWorker } from './base/index.js';
|
|
3
|
+
export const MessageBrokerWorker = (url) => {
|
|
4
|
+
const { errorWorker, getChannel } = BaseMessageBrokerWorker(url);
|
|
5
5
|
const listenQueue = async (queueName, onMessage) => {
|
|
6
6
|
errorWorker.addCustomErrorInfo({ queueName, onMessage });
|
|
7
7
|
const { data: channel, customError } = getChannel();
|
|
@@ -35,8 +35,7 @@ export const MessageBrokerSingleton = (() => {
|
|
|
35
35
|
channel.sendToQueue(queueName, Buffer.from(stringify(message)));
|
|
36
36
|
};
|
|
37
37
|
return {
|
|
38
|
-
init,
|
|
39
38
|
listenQueue,
|
|
40
39
|
sendMessage,
|
|
41
40
|
};
|
|
42
|
-
}
|
|
41
|
+
};
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import { MessageBrokerQueueName } from '../../message-broker-queue-name/index.js';
|
|
2
2
|
import { MessageBroker } from '../domains.js';
|
|
3
|
+
export type TMessageBrokerWorker = (url: string) => {
|
|
4
|
+
listenQueue: ListenQueue;
|
|
5
|
+
sendMessage: SendMessage;
|
|
6
|
+
};
|
|
3
7
|
export type ListenQueue = <T extends MessageBrokerQueueName>(queueName: T, onMessage: (message: MessageBroker[T]) => void) => Promise<void>;
|
|
4
8
|
export type SendMessage = <T extends MessageBrokerQueueName>(queueName: T, message: MessageBroker[T]) => Promise<void>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { MessageBroker } from '../message-broker/
|
|
1
|
+
import { MessageBroker } from '../message-broker/index.js';
|
|
2
2
|
export type MessageBrokerQueueName = keyof MessageBroker;
|
package/package.json
CHANGED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { GetChannel, Init } from './type.js';
|
|
2
|
-
export declare const BaseMessageBrokerSingleton: {
|
|
3
|
-
errorWorker: {
|
|
4
|
-
addCustomErrorInfo: import("../../../../common/custom-error/workers/type.js").AddCustomErrorInfo;
|
|
5
|
-
addCustomErrorMessage: import("../../../../common/custom-error/workers/type.js").AddCustomErrorMessage;
|
|
6
|
-
composeCustomError: import("../../../../common/custom-error/workers/type.js").ComposeCustomError;
|
|
7
|
-
getCustomError: import("../../../../common/custom-error/workers/type.js").GetCustomError;
|
|
8
|
-
resetCustomError: import("../../../../common/custom-error/workers/type.js").ResetCustomError;
|
|
9
|
-
};
|
|
10
|
-
getChannel: GetChannel;
|
|
11
|
-
init: Init;
|
|
12
|
-
};
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import amqp from 'amqplib';
|
|
2
|
-
import { CustomError, TCustomError } from '../../../../common/index.js';
|
|
3
|
-
export type _Connect = () => Promise<void>;
|
|
4
|
-
export type _HandleError = (err: unknown) => void;
|
|
5
|
-
export type GetChannel = () => TCustomError<amqp.Channel>;
|
|
6
|
-
export type Init = (url: string) => {
|
|
7
|
-
customError: CustomError;
|
|
8
|
-
} | undefined;
|
|
File without changes
|
|
File without changes
|