@platform-x/hep-message-broker-client 1.0.0

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.
Files changed (42) hide show
  1. package/README.md +1 -0
  2. package/dist/src/Util/commonUtil.d.ts +16 -0
  3. package/dist/src/Util/commonUtil.js +39 -0
  4. package/dist/src/Util/logger.d.ts +68 -0
  5. package/dist/src/Util/logger.js +195 -0
  6. package/dist/src/Util/requestTracer.d.ts +7 -0
  7. package/dist/src/Util/requestTracer.js +34 -0
  8. package/dist/src/config/ConfigManager.d.ts +9 -0
  9. package/dist/src/config/ConfigManager.js +67 -0
  10. package/dist/src/config/index.d.ts +29 -0
  11. package/dist/src/config/index.js +38 -0
  12. package/dist/src/index.d.ts +2 -0
  13. package/dist/src/index.js +6 -0
  14. package/dist/src/messageBroker/BaseRabbitMQClient.d.ts +16 -0
  15. package/dist/src/messageBroker/BaseRabbitMQClient.js +29 -0
  16. package/dist/src/messageBroker/ConnectionManager.d.ts +60 -0
  17. package/dist/src/messageBroker/ConnectionManager.js +227 -0
  18. package/dist/src/messageBroker/MessageBrokerClient.d.ts +34 -0
  19. package/dist/src/messageBroker/MessageBrokerClient.js +102 -0
  20. package/dist/src/messageBroker/MessageConsumer.d.ts +26 -0
  21. package/dist/src/messageBroker/MessageConsumer.js +102 -0
  22. package/dist/src/messageBroker/MessageProducer.d.ts +29 -0
  23. package/dist/src/messageBroker/MessageProducer.js +130 -0
  24. package/dist/src/messageBroker/RabbitMQClient.d.ts +12 -0
  25. package/dist/src/messageBroker/RabbitMQClient.js +67 -0
  26. package/dist/src/messageBroker/RetryManager.d.ts +23 -0
  27. package/dist/src/messageBroker/RetryManager.js +72 -0
  28. package/dist/src/messageBroker/interface/ConnectionWrapper.d.ts +6 -0
  29. package/dist/src/messageBroker/interface/ConnectionWrapper.js +3 -0
  30. package/dist/src/messageBroker/interface/IMessageBrokerClient.d.ts +7 -0
  31. package/dist/src/messageBroker/interface/IMessageBrokerClient.js +3 -0
  32. package/dist/src/messageBroker/rabbitmq/MessageBrokerClient.d.ts +114 -0
  33. package/dist/src/messageBroker/rabbitmq/MessageBrokerClient.js +706 -0
  34. package/dist/src/messageBroker/types/ActionType.d.ts +1 -0
  35. package/dist/src/messageBroker/types/ActionType.js +3 -0
  36. package/dist/src/messageBroker/types/PublishMessageInputType.d.ts +7 -0
  37. package/dist/src/messageBroker/types/PublishMessageInputType.js +3 -0
  38. package/dist/src/models/MessageModel.d.ts +5 -0
  39. package/dist/src/models/MessageModel.js +15 -0
  40. package/dist/src/models/NotificationMessageModel.d.ts +0 -0
  41. package/dist/src/models/NotificationMessageModel.js +2 -0
  42. package/package.json +40 -0
package/README.md ADDED
@@ -0,0 +1 @@
1
+ # hep-message-broker-client
@@ -0,0 +1,16 @@
1
+ /**
2
+ * stringToBase64 - to convert string into base64
3
+ * @param {string} toEncode- string request
4
+ */
5
+ export declare const stringToBase64: (toEncode: string) => string;
6
+ /**
7
+ * singleJSONParseHandler - to parse the json
8
+ * @param jsonString
9
+ * @param defaultValue
10
+ */
11
+ export declare const singleJSONParseHandler: (jsonString: string, defaultValue: any) => any;
12
+ /**
13
+ * Function to generate a correlation ID for tracing
14
+ * @returns
15
+ */
16
+ export declare const generateCorrelationId: () => string;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateCorrelationId = exports.singleJSONParseHandler = exports.stringToBase64 = void 0;
4
+ const logger_1 = require("./logger");
5
+ const requestTracer_1 = require("./requestTracer");
6
+ /**
7
+ * stringToBase64 - to convert string into base64
8
+ * @param {string} toEncode- string request
9
+ */
10
+ const stringToBase64 = (toEncode) => {
11
+ return Buffer.from(toEncode, 'ascii').toString('base64');
12
+ };
13
+ exports.stringToBase64 = stringToBase64;
14
+ /**
15
+ * singleJSONParseHandler - to parse the json
16
+ * @param jsonString
17
+ * @param defaultValue
18
+ */
19
+ const singleJSONParseHandler = (jsonString, defaultValue) => {
20
+ try {
21
+ return JSON.parse(jsonString);
22
+ }
23
+ catch (err) {
24
+ logger_1.Logger.warn(`Error while parsing JSON for value ${jsonString}`, 'doubleJSONParseHandler');
25
+ return defaultValue;
26
+ }
27
+ };
28
+ exports.singleJSONParseHandler = singleJSONParseHandler;
29
+ /**
30
+ * Function to generate a correlation ID for tracing
31
+ * @returns
32
+ */
33
+ const generateCorrelationId = () => {
34
+ const traceId = (0, requestTracer_1.getTraceId)() ? (0, requestTracer_1.getTraceId)() : 'trace-id';
35
+ const messageId = Math.random().toString(36).substring(2);
36
+ return `${traceId}__${messageId}`;
37
+ };
38
+ exports.generateCorrelationId = generateCorrelationId;
39
+ //# sourceMappingURL=commonUtil.js.map
@@ -0,0 +1,68 @@
1
+ export interface payLoadInterface {
2
+ statusCode?: number;
3
+ data?: any;
4
+ }
5
+ export interface LoggerInterface {
6
+ info(message: string, method: string): void;
7
+ warn(message: string, method: string, payload?: object): void;
8
+ error(message: string, method: string, payload?: object): void;
9
+ debug(message: string, method: string, payload?: object): void;
10
+ }
11
+ export declare class LoggerClass implements LoggerInterface {
12
+ private logger;
13
+ private infoLevel;
14
+ private debugLevel;
15
+ private errorLevel;
16
+ private warnLevel;
17
+ private blockedKeywords;
18
+ constructor();
19
+ /**
20
+ * It's written to handle JSON.circular error
21
+ * @param obj
22
+ * @returns
23
+ */
24
+ customstringify(obj: any): string;
25
+ /**
26
+ * for info log
27
+ * @param message
28
+ * @param payload
29
+ * @param method
30
+ * @returns
31
+ */
32
+ info(message: string, method: string): void;
33
+ /**
34
+ * for warn log
35
+ * @param message
36
+ * @param payload
37
+ * @param method
38
+ * @returns
39
+ */
40
+ warn(message: string, method: string, payload?: any): void;
41
+ /**
42
+ * for error log
43
+ * @param message
44
+ * @param payload
45
+ * @param method
46
+ * @returns
47
+ */
48
+ error(message: string, method: string, payload?: any): void;
49
+ /**
50
+ * for debug log
51
+ * @param message
52
+ * @param payload
53
+ * @param method
54
+ * @returns
55
+ */
56
+ debug(message: string, method: string, payload?: any): void;
57
+ /**
58
+ * to map log levels and handle from config
59
+ */
60
+ private mapLogLevels;
61
+ /**
62
+ * to sanitize logs from unwanted fields to be shown
63
+ * @param request
64
+ * @returns
65
+ */
66
+ private sanitizeLog;
67
+ }
68
+ export declare const Logger: LoggerClass;
@@ -0,0 +1,195 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.Logger = exports.LoggerClass = void 0;
7
+ const bunyan_1 = __importDefault(require("bunyan"));
8
+ const index_1 = __importDefault(require("../config/index"));
9
+ const bunyan_format_1 = __importDefault(require("bunyan-format"));
10
+ const requestTracer_1 = require("./requestTracer");
11
+ class LoggerClass {
12
+ constructor() {
13
+ this.infoLevel = false;
14
+ this.debugLevel = false;
15
+ this.errorLevel = false;
16
+ this.warnLevel = false;
17
+ this.blockedKeywords = ['currentPassword', 'clientSecret', 'newPassword'];
18
+ this.mapLogLevels();
19
+ this.logger = bunyan_1.default.createLogger({
20
+ name: index_1.default.APP_NAME,
21
+ level: 'trace', // by default enabling all levels, controlled through env separately
22
+ stream: (0, bunyan_format_1.default)({
23
+ outputMode: index_1.default.NODE_ENV === 'development' ? 'short' : 'bunyan',
24
+ levelInString: true,
25
+ color: true,
26
+ }),
27
+ });
28
+ }
29
+ /**
30
+ * It's written to handle JSON.circular error
31
+ * @param obj
32
+ * @returns
33
+ */
34
+ customstringify(obj) {
35
+ let cache = [];
36
+ let str = JSON.stringify(obj, (key, value) => {
37
+ {
38
+ this.info(`Logger customstringify ${key}`, 'customstringify');
39
+ if (typeof value === 'object' && value !== null) {
40
+ if (cache.indexOf(value) !== -1) {
41
+ // Circular reference found, discard key
42
+ return;
43
+ }
44
+ // Store value in our collection
45
+ cache.push(value);
46
+ }
47
+ return value;
48
+ }
49
+ });
50
+ cache = null; // reset the cache
51
+ return str;
52
+ }
53
+ /**
54
+ * for info log
55
+ * @param message
56
+ * @param payload
57
+ * @param method
58
+ * @returns
59
+ */
60
+ info(message, method) {
61
+ if (!this.infoLevel) {
62
+ return;
63
+ }
64
+ let loggerParams = {
65
+ message,
66
+ method,
67
+ traceId: (0, requestTracer_1.getTraceId)(),
68
+ };
69
+ this.logger.info(` start ${JSON.stringify(loggerParams)}==end`);
70
+ }
71
+ /**
72
+ * for warn log
73
+ * @param message
74
+ * @param payload
75
+ * @param method
76
+ * @returns
77
+ */
78
+ warn(message, method, payload) {
79
+ if (!this.warnLevel) {
80
+ return;
81
+ }
82
+ let loggerParams = {
83
+ message,
84
+ method,
85
+ traceId: (0, requestTracer_1.getTraceId)(),
86
+ statusCode: payload === null || payload === void 0 ? void 0 : payload.statusCode,
87
+ };
88
+ let finalPayload = (payload === null || payload === void 0 ? void 0 : payload.length) ? payload : {};
89
+ this.logger.warn(` start ${JSON.stringify(loggerParams)} payload: ${this.customstringify(this.sanitizeLog(finalPayload))}==end`);
90
+ }
91
+ /**
92
+ * for error log
93
+ * @param message
94
+ * @param payload
95
+ * @param method
96
+ * @returns
97
+ */
98
+ error(message, method, payload) {
99
+ if (!this.errorLevel) {
100
+ return;
101
+ }
102
+ if (payload instanceof Error) {
103
+ payload = {
104
+ message,
105
+ method,
106
+ traceId: (0, requestTracer_1.getTraceId)(),
107
+ stack: payload === null || payload === void 0 ? void 0 : payload.stack,
108
+ };
109
+ }
110
+ let loggerParams = {
111
+ message,
112
+ method,
113
+ traceId: (0, requestTracer_1.getTraceId)(),
114
+ spanId: (0, requestTracer_1.getSpanId)(),
115
+ statusCode: payload === null || payload === void 0 ? void 0 : payload.statusCode,
116
+ };
117
+ let finalPayload = (payload === null || payload === void 0 ? void 0 : payload.length) ? payload : {};
118
+ this.logger.error(` start ${JSON.stringify(loggerParams)} payload: ${this.customstringify(this.sanitizeLog(finalPayload))}==end`);
119
+ }
120
+ /**
121
+ * for debug log
122
+ * @param message
123
+ * @param payload
124
+ * @param method
125
+ * @returns
126
+ */
127
+ debug(message, method, payload) {
128
+ if (!this.debugLevel) {
129
+ return;
130
+ }
131
+ let loggerParams = {
132
+ message,
133
+ method,
134
+ traceId: (0, requestTracer_1.getTraceId)(),
135
+ statusCode: payload === null || payload === void 0 ? void 0 : payload.statusCode,
136
+ };
137
+ let finalPayload = (payload === null || payload === void 0 ? void 0 : payload.length) ? payload : {};
138
+ this.logger.debug(` start ${JSON.stringify(loggerParams)} payload: ${this.customstringify(this.sanitizeLog(finalPayload))}==end`);
139
+ }
140
+ /**
141
+ * to map log levels and handle from config
142
+ */
143
+ mapLogLevels() {
144
+ if (index_1.default.LOG_LEVELS.length) {
145
+ index_1.default.LOG_LEVELS.forEach((element) => {
146
+ const logLevel = element.trim();
147
+ if (logLevel === 'info') {
148
+ this.infoLevel = true;
149
+ }
150
+ else if (logLevel === 'debug') {
151
+ this.debugLevel = true;
152
+ }
153
+ else if (logLevel === 'error') {
154
+ this.errorLevel = true;
155
+ }
156
+ else if (logLevel === 'warn') {
157
+ this.warnLevel = true;
158
+ }
159
+ });
160
+ }
161
+ }
162
+ /**
163
+ * to sanitize logs from unwanted fields to be shown
164
+ * @param request
165
+ * @returns
166
+ */
167
+ sanitizeLog(request) {
168
+ try {
169
+ if (request) {
170
+ // let obj: any = {};
171
+ Object.keys(request).forEach((key) => {
172
+ let value = request[key];
173
+ if (request[key] === 'options') {
174
+ delete request.options;
175
+ }
176
+ else {
177
+ if (this.blockedKeywords.find((blockedKey) => key.toLowerCase() === blockedKey.toLowerCase())) {
178
+ request[key] = 'XXXXXXXXXX';
179
+ }
180
+ else {
181
+ request[key] = value;
182
+ }
183
+ }
184
+ });
185
+ return request;
186
+ }
187
+ }
188
+ catch (err) {
189
+ this.error('Logger sanitize error', err);
190
+ }
191
+ }
192
+ }
193
+ exports.LoggerClass = LoggerClass;
194
+ exports.Logger = new LoggerClass();
195
+ //# sourceMappingURL=logger.js.map
@@ -0,0 +1,7 @@
1
+ import { NextFunction, Request, Response } from 'express';
2
+ /**
3
+ * setTracers - to set the request tracers on the request
4
+ */
5
+ export declare const setTracers: (req: Request, res: Response, next: NextFunction) => void;
6
+ export declare const getTraceId: () => any;
7
+ export declare const getSpanId: () => any;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getSpanId = exports.getTraceId = exports.setTracers = void 0;
7
+ const cls_hooked_1 = __importDefault(require("cls-hooked"));
8
+ const uuid_1 = require("uuid");
9
+ const TRACE_ID_HEADER_NAME = 'Platform-X-Trace-Id';
10
+ const nsid = `rtracer:${(0, uuid_1.v4)()}`;
11
+ const ns = cls_hooked_1.default.createNamespace(nsid);
12
+ const traceIdKey = 'traceId';
13
+ const spanIdKey = 'spanId';
14
+ /**
15
+ * setTracers - to set the request tracers on the request
16
+ */
17
+ const setTracers = (req, res, next) => {
18
+ const headerName = TRACE_ID_HEADER_NAME.toLocaleLowerCase();
19
+ ns.bindEmitter(req);
20
+ ns.bindEmitter(res);
21
+ const traceId = req.headers[headerName] || (0, uuid_1.v4)(); // to be passed in headers
22
+ const spanId = (0, uuid_1.v4)(); // will be unique for services
23
+ ns.run(() => {
24
+ ns.set(traceIdKey, traceId);
25
+ ns.set(spanIdKey, spanId);
26
+ next();
27
+ });
28
+ };
29
+ exports.setTracers = setTracers;
30
+ const getTraceId = () => ns.get(traceIdKey);
31
+ exports.getTraceId = getTraceId;
32
+ const getSpanId = () => ns.get(spanIdKey);
33
+ exports.getSpanId = getSpanId;
34
+ //# sourceMappingURL=requestTracer.js.map
@@ -0,0 +1,9 @@
1
+ declare class ConfigManager {
2
+ private static instance;
3
+ private config;
4
+ private constructor();
5
+ static getInstance(): ConfigManager;
6
+ loadConfig(configPath: string): void;
7
+ getConfig(): any;
8
+ }
9
+ export default ConfigManager;
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ const fs = __importStar(require("fs"));
40
+ const index_1 = __importDefault(require("./index"));
41
+ const logger_1 = require("../Util/logger");
42
+ class ConfigManager {
43
+ constructor() {
44
+ this.config = {};
45
+ this.loadConfig(index_1.default.RABBITMQ.CONFIG_PATH);
46
+ }
47
+ static getInstance() {
48
+ if (!ConfigManager.instance) {
49
+ ConfigManager.instance = new ConfigManager();
50
+ }
51
+ return ConfigManager.instance;
52
+ }
53
+ loadConfig(configPath) {
54
+ if (fs.existsSync(configPath)) {
55
+ // Do something
56
+ this.config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
57
+ }
58
+ else {
59
+ logger_1.Logger.error("Config file missing!", "loadConfig");
60
+ }
61
+ }
62
+ getConfig() {
63
+ return this.config;
64
+ }
65
+ }
66
+ exports.default = ConfigManager;
67
+ //# sourceMappingURL=ConfigManager.js.map
@@ -0,0 +1,29 @@
1
+ declare const _default: {
2
+ LOG_LEVELS: string[];
3
+ NODE_ENV: string;
4
+ APP_NAME: string;
5
+ RABBITMQ: {
6
+ USER: string;
7
+ PASS: string;
8
+ HOST: string;
9
+ PORT: string;
10
+ MAIN_QUEUE: string;
11
+ MAIN_EXCHANGE: string;
12
+ DLX_QUEUE: string;
13
+ DLX_EXCHANGE: string;
14
+ RETRY_QUEUE: string;
15
+ RETRY_EXCHANGE: string;
16
+ MAX_RETRIES: number;
17
+ HEARTBEAT: number;
18
+ TTL: string;
19
+ BACKOFF_TIME: number;
20
+ IS_ENABLED: string;
21
+ RABBITMQ_CONFIG: string;
22
+ PREFETCH_COUNT: number;
23
+ CONNECTION_ERROR: string | boolean;
24
+ PUBLISHER_ERROR: string | boolean;
25
+ CONSUMER_ERROR: string | boolean;
26
+ CONFIG_PATH: string;
27
+ };
28
+ };
29
+ export default _default;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ const dotenv_1 = __importDefault(require("dotenv"));
8
+ dotenv_1.default.config();
9
+ process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
10
+ exports.default = {
11
+ LOG_LEVELS: ['info', 'error', 'warn', 'debug'],
12
+ NODE_ENV: 'development',
13
+ APP_NAME: 'hep-message-broker-client',
14
+ RABBITMQ: {
15
+ USER: (_a = process.env.RABBITMQ_USER) !== null && _a !== void 0 ? _a : 'root',
16
+ PASS: (_b = process.env.RABBITMQ_PASS) !== null && _b !== void 0 ? _b : 'root',
17
+ HOST: (_c = process.env.RABBITMQ_HOST) !== null && _c !== void 0 ? _c : '127.0.0.1',
18
+ PORT: (_d = process.env.RABBITMQ_PORT) !== null && _d !== void 0 ? _d : '5672',
19
+ MAIN_QUEUE: 'main_queue',
20
+ MAIN_EXCHANGE: 'assets_metadata_generate_exchange',
21
+ DLX_QUEUE: 'dead_letter_queue',
22
+ DLX_EXCHANGE: 'assets_dlx_exchange',
23
+ RETRY_QUEUE: 'retry_queue',
24
+ RETRY_EXCHANGE: 'assets_metadata_generate_retry_exchange',
25
+ MAX_RETRIES: Number((_f = (_e = process.env.RABBITMQ_MAX_RETRIES) === null || _e === void 0 ? void 0 : _e.trim()) !== null && _f !== void 0 ? _f : 1),
26
+ HEARTBEAT: Number((_h = (_g = process.env.RABBITMQ_HEARTBEAT) === null || _g === void 0 ? void 0 : _g.trim()) !== null && _h !== void 0 ? _h : 5),
27
+ TTL: (_j = process.env.RABBITMQ_TTL) !== null && _j !== void 0 ? _j : "3000|6000|9000",
28
+ BACKOFF_TIME: Number((_l = (_k = process.env.BACKOFF_TIME) === null || _k === void 0 ? void 0 : _k.trim()) !== null && _l !== void 0 ? _l : 1000),
29
+ IS_ENABLED: (_m = process.env.RABBITMQ_IS_ENABLED) !== null && _m !== void 0 ? _m : 'true',
30
+ RABBITMQ_CONFIG: (_o = process.env.RABBITMQ_CONFIG) !== null && _o !== void 0 ? _o : '',
31
+ PREFETCH_COUNT: Number((_p = process.env.RABBITMQ_PREFETCH) !== null && _p !== void 0 ? _p : 50),
32
+ CONNECTION_ERROR: (_q = process.env.RABBITMQ_CONNECTION_ERROR) !== null && _q !== void 0 ? _q : false,
33
+ PUBLISHER_ERROR: (_r = process.env.RABBITMQ_PUBLISHER_ERROR) !== null && _r !== void 0 ? _r : false,
34
+ CONSUMER_ERROR: (_s = process.env.RABBITMQ_CONSUMER_ERROR) !== null && _s !== void 0 ? _s : false,
35
+ CONFIG_PATH: (_t = process.env.CONFIG_PATH) !== null && _t !== void 0 ? _t : '/etc/rabbitmq/rabbitMQConfig.json',
36
+ }
37
+ };
38
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,2 @@
1
+ import { MessageBrokerClient } from "./messageBroker/rabbitmq/MessageBrokerClient";
2
+ export { MessageBrokerClient };
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MessageBrokerClient = void 0;
4
+ const MessageBrokerClient_1 = require("./messageBroker/rabbitmq/MessageBrokerClient");
5
+ Object.defineProperty(exports, "MessageBrokerClient", { enumerable: true, get: function () { return MessageBrokerClient_1.MessageBrokerClient; } });
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,16 @@
1
+ import * as amqp from 'amqplib';
2
+ import ConfigManager from '../config/ConfigManager';
3
+ import ConnectionManager from './ConnectionManager';
4
+ declare class BaseRabbitMQClient {
5
+ readonly configManager: ConfigManager;
6
+ readonly connectionManager: ConnectionManager;
7
+ protected connection: amqp.Connection | undefined;
8
+ protected channel: amqp.Channel | undefined;
9
+ protected configData: any;
10
+ constructor();
11
+ /**
12
+ * Function for load the config data
13
+ */
14
+ private init;
15
+ }
16
+ export default BaseRabbitMQClient;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const ConfigManager_1 = __importDefault(require("../config/ConfigManager"));
7
+ const config_1 = __importDefault(require("../config"));
8
+ const ConnectionManager_1 = __importDefault(require("./ConnectionManager"));
9
+ class BaseRabbitMQClient {
10
+ constructor() {
11
+ this.connectionManager = new ConnectionManager_1.default();
12
+ this.configData = {};
13
+ this.configManager = ConfigManager_1.default.getInstance();
14
+ this.configData = this.configManager.getConfig();
15
+ this.channel = this.connectionManager.getChannel();
16
+ this.connection = this.connectionManager.getConnection();
17
+ this.init();
18
+ }
19
+ /**
20
+ * Function for load the config data
21
+ */
22
+ init() {
23
+ var _a;
24
+ this.configManager.loadConfig((_a = config_1.default === null || config_1.default === void 0 ? void 0 : config_1.default.RABBITMQ) === null || _a === void 0 ? void 0 : _a.CONFIG_PATH);
25
+ this.configData = this.configManager.getConfig();
26
+ }
27
+ }
28
+ exports.default = BaseRabbitMQClient;
29
+ //# sourceMappingURL=BaseRabbitMQClient.js.map
@@ -0,0 +1,60 @@
1
+ import * as amqp from 'amqplib';
2
+ interface ConnectionWrapper {
3
+ connection: amqp.Connection;
4
+ channel: amqp.Channel;
5
+ }
6
+ declare class ConnectionManager {
7
+ private static instance;
8
+ private readonly configManager;
9
+ protected connection: amqp.Connection | undefined;
10
+ protected channel: amqp.Channel | undefined;
11
+ protected configData: any;
12
+ constructor();
13
+ /**
14
+ * Function for get channel
15
+ */
16
+ getChannel(): amqp.Channel | undefined;
17
+ /**
18
+ * Function for get channel
19
+ */
20
+ getConnection(): amqp.Connection | undefined;
21
+ /**
22
+ * Function for create and return intance
23
+ * @returns
24
+ */
25
+ static getInstance(): Promise<ConnectionManager>;
26
+ /**
27
+ * Function to connect create to RabbitMQ
28
+ */
29
+ createConnection(): Promise<ConnectionWrapper>;
30
+ /**
31
+ * Function for bind connection event handler on close and error setupQueuesAndExchanges
32
+ * @returns
33
+ */
34
+ private bindConnectionEventHandler;
35
+ /**
36
+ * Function to check the status of the connection
37
+ * @returns boolean
38
+ */
39
+ isConnected(): Promise<boolean>;
40
+ /**
41
+ * Function to initialize the connection, channel and setup the queues and exchanges
42
+ * @param reqData
43
+ * @returns
44
+ */
45
+ initialize(): Promise<{
46
+ connection: amqp.Connection | undefined;
47
+ channel: amqp.Channel | undefined;
48
+ } | undefined>;
49
+ /**
50
+ * Function to setup the queues and exchanges
51
+ * @params array
52
+ * @rtrun
53
+ */
54
+ private setupQueuesAndExchanges;
55
+ /**
56
+ * Function for load the config data
57
+ */
58
+ private init;
59
+ }
60
+ export default ConnectionManager;