@seidor-cloud-produtos/orbit-backend-lib 2.0.51 → 2.0.53
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/clean-arch/application/logger/index.d.ts +2 -2
- package/dist/clean-arch/application/logger/index.js +3 -3
- package/dist/clean-arch/infra/logger/logger-in-memory.d.ts +1 -1
- package/dist/clean-arch/infra/logger/logger-in-memory.js +2 -2
- package/dist/clean-arch/infra/logger/logger-orbit.d.ts +1 -1
- package/dist/clean-arch/infra/logger/logger-orbit.js +2 -2
- package/dist/clean-arch/infra/queue/rabbitmq/amqp-lib.d.ts +3 -1
- package/dist/clean-arch/infra/queue/rabbitmq/amqp-lib.js +19 -17
- package/package.json +1 -1
|
@@ -32,9 +32,9 @@ export interface Logger {
|
|
|
32
32
|
}
|
|
33
33
|
export default abstract class LoggerGateway implements Logger {
|
|
34
34
|
protected cache: Cache;
|
|
35
|
-
protected params?: LogParams | undefined;
|
|
36
35
|
protected options?: LogOptions | undefined;
|
|
37
|
-
|
|
36
|
+
protected params?: LogParams | undefined;
|
|
37
|
+
constructor(cache: Cache, options?: LogOptions | undefined, params?: LogParams | undefined);
|
|
38
38
|
private static cacheKey;
|
|
39
39
|
info(...input: any[]): Promise<void>;
|
|
40
40
|
warn(...input: any[]): Promise<void>;
|
|
@@ -14,12 +14,12 @@ var CategoryEnum;
|
|
|
14
14
|
})(CategoryEnum || (exports.CategoryEnum = CategoryEnum = {}));
|
|
15
15
|
class LoggerGateway {
|
|
16
16
|
cache;
|
|
17
|
-
params;
|
|
18
17
|
options;
|
|
19
|
-
|
|
18
|
+
params;
|
|
19
|
+
constructor(cache, options, params) {
|
|
20
20
|
this.cache = cache;
|
|
21
|
-
this.params = params;
|
|
22
21
|
this.options = options;
|
|
22
|
+
this.params = params;
|
|
23
23
|
}
|
|
24
24
|
static cacheKey = 'LOG_LEVEL';
|
|
25
25
|
async info(...input) {
|
|
@@ -5,7 +5,7 @@ export interface LoggerInMemoryOptions extends LogOptions {
|
|
|
5
5
|
}
|
|
6
6
|
export declare class LoggerInMemory extends LoggerGateway {
|
|
7
7
|
protected options: LoggerInMemoryOptions;
|
|
8
|
-
constructor(cache: Cache,
|
|
8
|
+
constructor(cache: Cache, options?: LoggerInMemoryOptions, params?: LogParams);
|
|
9
9
|
log(props: LogPropertiesInput, dataToLog: any): Promise<void>;
|
|
10
10
|
protected register(props: LogPropertiesInput, dataToLog: any): void;
|
|
11
11
|
}
|
|
@@ -5,8 +5,8 @@ const tslib_1 = require("tslib");
|
|
|
5
5
|
const logger_1 = tslib_1.__importDefault(require("../../application/logger"));
|
|
6
6
|
const types_1 = require("../environment/types");
|
|
7
7
|
class LoggerInMemory extends logger_1.default {
|
|
8
|
-
constructor(cache,
|
|
9
|
-
super(cache,
|
|
8
|
+
constructor(cache, options, params) {
|
|
9
|
+
super(cache, options, params);
|
|
10
10
|
}
|
|
11
11
|
async log(props, dataToLog) {
|
|
12
12
|
return await super.log(props, dataToLog);
|
|
@@ -46,7 +46,7 @@ export declare class LoggerOrbit extends LoggerGateway {
|
|
|
46
46
|
private queue;
|
|
47
47
|
protected options: LoggerOrbitOptions;
|
|
48
48
|
protected params?: LogOrbitParams;
|
|
49
|
-
constructor(queue: Queue, cache: Cache,
|
|
49
|
+
constructor(queue: Queue, cache: Cache, options?: LoggerOrbitOptions, params?: LogOrbitParams);
|
|
50
50
|
log(props: LogOrbitPropertiesInput, dataToLog: any): Promise<void>;
|
|
51
51
|
protected isToLog(props: LogOrbitProperties, dataToLog: any): Promise<boolean>;
|
|
52
52
|
register(props: LogOrbitProperties, data: any): Promise<void>;
|
|
@@ -15,8 +15,8 @@ class LogEvent {
|
|
|
15
15
|
exports.default = LogEvent;
|
|
16
16
|
class LoggerOrbit extends logger_1.default {
|
|
17
17
|
queue;
|
|
18
|
-
constructor(queue, cache,
|
|
19
|
-
super(cache,
|
|
18
|
+
constructor(queue, cache, options, params) {
|
|
19
|
+
super(cache, options, params);
|
|
20
20
|
this.queue = queue;
|
|
21
21
|
}
|
|
22
22
|
async log(props, dataToLog) {
|
|
@@ -4,6 +4,7 @@ import QueueConnection from '../../../application/queue/queue-connection';
|
|
|
4
4
|
import DomainEvent from '../../../domain/events/domain-event';
|
|
5
5
|
import QueueController from '../queue-controller';
|
|
6
6
|
import { AmqpQueueGetResult } from './types';
|
|
7
|
+
import { Logger } from '../../../application/logger';
|
|
7
8
|
interface SocketOptions {
|
|
8
9
|
retry?: {
|
|
9
10
|
maxCount: number;
|
|
@@ -11,6 +12,7 @@ interface SocketOptions {
|
|
|
11
12
|
};
|
|
12
13
|
}
|
|
13
14
|
export default class AmqpQueue implements QueueConnection {
|
|
15
|
+
protected logger: Logger;
|
|
14
16
|
private uri;
|
|
15
17
|
private static instance;
|
|
16
18
|
private vHost;
|
|
@@ -19,7 +21,7 @@ export default class AmqpQueue implements QueueConnection {
|
|
|
19
21
|
private controller;
|
|
20
22
|
private channels;
|
|
21
23
|
protected socketOptions?: SocketOptions;
|
|
22
|
-
constructor(socketOptions?: SocketOptions, uri?: string);
|
|
24
|
+
constructor(socketOptions?: SocketOptions, uri?: string, logger?: Logger);
|
|
23
25
|
private setSocketOptions;
|
|
24
26
|
connect(vHost: string, retryCount?: number): Promise<AmqpQueue>;
|
|
25
27
|
close(): Promise<void>;
|
|
@@ -4,6 +4,7 @@ const tslib_1 = require("tslib");
|
|
|
4
4
|
const amqplib_1 = tslib_1.__importDefault(require("amqplib"));
|
|
5
5
|
const timeout_1 = require("../../../shared/timeout");
|
|
6
6
|
class AmqpQueue {
|
|
7
|
+
logger;
|
|
7
8
|
uri;
|
|
8
9
|
static instance;
|
|
9
10
|
vHost;
|
|
@@ -12,7 +13,8 @@ class AmqpQueue {
|
|
|
12
13
|
controller;
|
|
13
14
|
channels = new Map();
|
|
14
15
|
socketOptions;
|
|
15
|
-
constructor(socketOptions, uri = process.env.BROKER_AMQP) {
|
|
16
|
+
constructor(socketOptions, uri = process.env.BROKER_AMQP, logger = console) {
|
|
17
|
+
this.logger = logger;
|
|
16
18
|
this.uri = uri;
|
|
17
19
|
this.setSocketOptions(socketOptions);
|
|
18
20
|
}
|
|
@@ -27,8 +29,8 @@ class AmqpQueue {
|
|
|
27
29
|
this.vHost = vHost;
|
|
28
30
|
await this.treatReconnection(vHost);
|
|
29
31
|
if (process.env.NODE_ENV !== 'test') {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
+
this.logger.info(`⚙️ PROCESS ${this.vHost} PID: `, process.pid);
|
|
33
|
+
this.logger.info(`🐝 Queue connected on vHost: ${this.vHost}`);
|
|
32
34
|
}
|
|
33
35
|
return this;
|
|
34
36
|
}
|
|
@@ -37,7 +39,7 @@ class AmqpQueue {
|
|
|
37
39
|
retryCount >= this.socketOptions?.retry?.maxCount) {
|
|
38
40
|
throw e;
|
|
39
41
|
}
|
|
40
|
-
|
|
42
|
+
this.logger.info(`Retrying connection in... ${this.socketOptions.retry.intervalMs || 0}ms`);
|
|
41
43
|
await (0, timeout_1.sleep)(this.socketOptions.retry.intervalMs);
|
|
42
44
|
return await this.connect(vHost, retryCount++);
|
|
43
45
|
}
|
|
@@ -45,7 +47,7 @@ class AmqpQueue {
|
|
|
45
47
|
async close() {
|
|
46
48
|
await this.connection.close();
|
|
47
49
|
if (process.env.NODE_ENV !== 'test') {
|
|
48
|
-
|
|
50
|
+
this.logger.info(`⛔ Queue closed on vHost ${this.vHost}`);
|
|
49
51
|
}
|
|
50
52
|
}
|
|
51
53
|
async get(queueName, options) {
|
|
@@ -59,7 +61,7 @@ class AmqpQueue {
|
|
|
59
61
|
return { rawMessage, channel };
|
|
60
62
|
}
|
|
61
63
|
catch (err) {
|
|
62
|
-
|
|
64
|
+
this.logger.info(`⛔ Erro ao obter mensagem de ${queueName}:`, err);
|
|
63
65
|
return null;
|
|
64
66
|
}
|
|
65
67
|
}
|
|
@@ -69,7 +71,7 @@ class AmqpQueue {
|
|
|
69
71
|
await channel.close();
|
|
70
72
|
}
|
|
71
73
|
catch (err) {
|
|
72
|
-
|
|
74
|
+
this.logger.info('⛔ Erro ao dar ack:', err);
|
|
73
75
|
}
|
|
74
76
|
}
|
|
75
77
|
async nack(channel, msg, requeue = false) {
|
|
@@ -78,7 +80,7 @@ class AmqpQueue {
|
|
|
78
80
|
await channel.close();
|
|
79
81
|
}
|
|
80
82
|
catch (err) {
|
|
81
|
-
|
|
83
|
+
this.logger.info('⛔ Erro ao dar nack:', err);
|
|
82
84
|
}
|
|
83
85
|
}
|
|
84
86
|
async on(queueName, callback) {
|
|
@@ -98,10 +100,10 @@ class AmqpQueue {
|
|
|
98
100
|
channel.reject(message, false);
|
|
99
101
|
}
|
|
100
102
|
});
|
|
101
|
-
|
|
103
|
+
this.logger.info(`🍯 Consume on queue: [${queueName}] on vHost ${this.vHost}`);
|
|
102
104
|
}
|
|
103
105
|
catch (err) {
|
|
104
|
-
|
|
106
|
+
this.logger.info({
|
|
105
107
|
message: `⛔ Error to consume messages: [${queueName}] on vHost ${this.vHost}`,
|
|
106
108
|
error: err,
|
|
107
109
|
});
|
|
@@ -128,7 +130,7 @@ class AmqpQueue {
|
|
|
128
130
|
domainEvent,
|
|
129
131
|
configs: buildedConfigs,
|
|
130
132
|
});
|
|
131
|
-
|
|
133
|
+
this.logger.info({
|
|
132
134
|
message: `⛔ Error to publish messages to: ${domainEvent.name}. Publish in memory!`,
|
|
133
135
|
error: err,
|
|
134
136
|
});
|
|
@@ -160,7 +162,7 @@ class AmqpQueue {
|
|
|
160
162
|
await channel.close();
|
|
161
163
|
}
|
|
162
164
|
catch (err) {
|
|
163
|
-
|
|
165
|
+
this.logger.info({
|
|
164
166
|
message: `⛔ Error to create queue: ${queueName} on vHost ${this.vHost}`,
|
|
165
167
|
error: err,
|
|
166
168
|
});
|
|
@@ -183,8 +185,8 @@ class AmqpQueue {
|
|
|
183
185
|
async treatReconnection(vHost) {
|
|
184
186
|
this.connection.removeAllListeners('close');
|
|
185
187
|
this.connection.on('close', async () => {
|
|
186
|
-
|
|
187
|
-
|
|
188
|
+
this.logger.info('⛔ Connection Closed!!');
|
|
189
|
+
this.logger.info(`🔄 Try connection to the vHost: ${vHost}`);
|
|
188
190
|
const interval = setInterval(async () => {
|
|
189
191
|
try {
|
|
190
192
|
AmqpQueue.instance = await this.connect(vHost);
|
|
@@ -194,7 +196,7 @@ class AmqpQueue {
|
|
|
194
196
|
clearInterval(interval);
|
|
195
197
|
}
|
|
196
198
|
catch {
|
|
197
|
-
|
|
199
|
+
this.logger.info(`🔄 Trying to connection to the vHost: ${vHost}`);
|
|
198
200
|
}
|
|
199
201
|
}, 5000);
|
|
200
202
|
});
|
|
@@ -209,9 +211,9 @@ class AmqpQueue {
|
|
|
209
211
|
while (this.messagesInMemory.length > 0) {
|
|
210
212
|
const data = this.messagesInMemory.shift();
|
|
211
213
|
await this.publish(data.exchangeName, data.domainEvent, data.configs);
|
|
212
|
-
|
|
214
|
+
this.logger.info(`✅ Publishing memory message to: [${data.domainEvent.name}]`);
|
|
213
215
|
}
|
|
214
|
-
|
|
216
|
+
this.logger.info('✅ Published memory messages!');
|
|
215
217
|
}
|
|
216
218
|
}
|
|
217
219
|
}
|