exodus-framework 2.0.787 → 2.0.788

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.
@@ -5,13 +5,15 @@ import { IService } from '../contracts/service';
5
5
  declare class RabbitMQService extends Service implements IService {
6
6
  connection: Connection;
7
7
  channel: Channel;
8
- private connected;
8
+ private connectionRetries;
9
9
  private mainRouter;
10
10
  private eventCustomListeners;
11
11
  constructor();
12
12
  init(): Promise<void>;
13
13
  registerHandles(): Promise<void>;
14
14
  connect(): Promise<void>;
15
+ private bindEvents;
16
+ reconnect(): void;
15
17
  sendToQueue<K extends keyof TMessageQueueDataMap>(topic: K, data: TMessageQueueDataMap[K]): Promise<`${string}-${string}-${string}-${string}-${string}`>;
16
18
  consumeFromQueue(msg: client.ConsumeMessage): Promise<void>;
17
19
  registerRouter(router: TMessagingQueueEventList): void;
@@ -1 +1 @@
1
- {"version":3,"file":"rabitmq.d.ts","sourceRoot":"","sources":["../../src/services/rabitmq.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAEtD,OAAO,OAAO,MAAM,gBAAgB,CAAC;AACrC,OAAO,EACL,oBAAoB,EACpB,wBAAwB,EACxB,sBAAsB,EACvB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAUhD,cAAM,eAAgB,SAAQ,OAAQ,YAAW,QAAQ;IACvD,UAAU,EAAG,UAAU,CAAC;IACxB,OAAO,EAAG,OAAO,CAAC;IAClB,OAAO,CAAC,SAAS,CAAW;IAC5B,OAAO,CAAC,UAAU,CAA2B;IAC7C,OAAO,CAAC,oBAAoB,CAA0D;;IAOhF,IAAI;IAMJ,eAAe;IAiBf,OAAO;IAwBP,WAAW,CAAC,CAAC,SAAS,MAAM,oBAAoB,EAAE,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,oBAAoB,CAAC,CA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AAU;IAUlB,SAAS;IAYH,WAAW,CAAC,CAAC,SAAS,MAAM,oBAAoB,EAAE,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,oBAAoB,CAAC,CAAC,CAAC;IAoBzF,gBAAgB,CAAC,GAAG,EAAE,MAAM,CAAC,cAAc;IA0BjD,cAAc,CAAC,MAAM,EAAE,wBAAwB;IAIxC,aAAa,CAAC,CAAC,SAAS,MAAM,oBAAoB,EACvD,KAAK,EAAE,CAAC,EACR,QAAQ,EAAE,sBAAsB,CAAC,CAAC,CAAC;IAY9B,cAAc,CAAC,CAAC,SAAS,MAAM,oBAAoB,EAAE,KAAK,EAAE,CAAC;IAW7D,YAAY,CACjB,CAAC,SAAS,MAAM,oBAAoB,EACpC,CAAC,SAAS,MAAM,oBAAoB,EACpC,IAAI,EAAE;QACN,IAAI,EAAE;YAAE,KAAK,EAAE,CAAC,CAAC;YAAC,IAAI,EAAE,oBAAoB,CAAC,CAAC,CAAC,CAAA;SAAE,CAAC;QAClD,MAAM,EAAE;YAAE,KAAK,EAAE,CAAC,CAAC;YAAC,QAAQ,EAAE,sBAAsB,CAAC,CAAC,CAAC,CAAA;SAAE,CAAC;KAC3D;CAUF;AAED,eAAe,eAAe,CAAC"}
@@ -20,7 +20,7 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
20
20
  class RabbitMQService extends _service.default {
21
21
  connection;
22
22
  channel;
23
- connected;
23
+ connectionRetries;
24
24
  mainRouter;
25
25
  eventCustomListeners;
26
26
 
@@ -28,6 +28,7 @@ class RabbitMQService extends _service.default {
28
28
  constructor() {
29
29
  super();
30
30
  this.eventCustomListeners = new Map();
31
+ this.connectionRetries = 0;
31
32
  }
32
33
  async init() {
33
34
  if (!this.mainRouter) throw new Error('Need router'); //!sem router
@@ -47,7 +48,6 @@ class RabbitMQService extends _service.default {
47
48
  });
48
49
  }
49
50
  async connect() {
50
- if (this.connected && this.channel) return;else this.connected = true;
51
51
  try {
52
52
  this.log(`⌛️ Connecting to Rabbit-MQ Server`);
53
53
  this.connection = await _amqplib.default.connect(`amqp://${_app.Core.settings.getMessaging().user}:${_app.Core.settings.getMessaging().pass}@${_app.Core.settings.getMessaging().host}:5672`);
@@ -59,12 +59,34 @@ class RabbitMQService extends _service.default {
59
59
  await this.channel.assertQueue(_app.Core.settings.getAppication().appId, {
60
60
  durable: true
61
61
  });
62
- this.log(`🛸 Created RabbitMQ Channel successfully`);
62
+ this.bindEvents();
63
63
  this.registerHandles();
64
+ this.log(`🛸 Created RabbitMQ Channel successfully`);
65
+ this.connectionRetries = 0;
64
66
  } catch (error) {
65
67
  throw new _app.ErrorHandler(`Not connected to MQ Server`, error); // ! throw because starting process
66
68
  }
67
69
  }
70
+ bindEvents() {
71
+ this.channel.on('error', err => {
72
+ new _app.ErrorHandler('falha no canal rabitmq', err);
73
+ this.reconnect();
74
+ });
75
+ this.channel.on('close', err => {
76
+ new _app.ErrorHandler('falha no canal rabitmq', err);
77
+ this.reconnect();
78
+ });
79
+ }
80
+ reconnect() {
81
+ if (this.connectionRetries >= 3) {
82
+ throw new Error(`Not possible to connect RabitMQ`);
83
+ }
84
+ setTimeout(() => {
85
+ this.connectionRetries += 1;
86
+ this.log('Tryning to connect RabbitMQ', 'warning');
87
+ this.connect();
88
+ }, 5000);
89
+ }
68
90
 
69
91
  //# Common
70
92
  async sendToQueue(topic, data) {
@@ -94,16 +116,17 @@ class RabbitMQService extends _service.default {
94
116
  const content = JSON.parse(msg.content.toString());
95
117
  const callBack = this.mainRouter[topic];
96
118
  if (callBack) {
97
- callBack(content.data, () => this.channel.ack(msg), content.serviceId, msg.properties.messageId);
119
+ callBack(content.data, () => {}, content.serviceId, msg.properties.messageId);
98
120
  }
121
+ this.channel.ack(msg); //# the next function is temporary and not confirm ack
122
+
99
123
  if (this.eventCustomListeners.has(topic)) {
100
124
  const cb = this.eventCustomListeners.get(topic);
101
- cb(content.data, () => this.channel.ack(msg), content.serviceId, msg.properties.messageId);
125
+ cb(content.data, () => {}, content.serviceId, msg.properties.messageId);
102
126
  }
103
127
  } catch (error) {
104
128
  new _app.ErrorHandler('Error on parsing message from queue', error);
105
- } finally {
106
- this.channel.ack(msg);
129
+ this.channel.nack(msg, false, false);
107
130
  }
108
131
  }
109
132
  registerRouter(router) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "exodus-framework",
3
- "version": "2.0.787",
3
+ "version": "2.0.788",
4
4
  "description": "Exodus Framework",
5
5
  "author": "jhownpaixao",
6
6
  "license": "ISC",