@go-mailer/vertebra 2.0.0 → 2.0.2

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.
@@ -1,16 +1,17 @@
1
1
  const rabbit = require("amqplib");
2
2
 
3
3
  class Broker {
4
- constructor({ host = "localhost", user = "guest", passwd = "guest", port = 5672}) {
4
+ constructor({ host = "localhost", user = "guest", passwd = "guest", port = 5672, onConnect = () => {}}) {
5
5
  this.url = `amqp://${user}:${passwd}@${host}:${port}`;
6
6
  this.channel = null;
7
+ this.onConnect = onConnect;
7
8
  }
8
9
 
9
10
  getChannel() {
10
11
  return this.channel;
11
12
  }
12
13
 
13
- async connect({ onConnect = () => {}}) {
14
+ async connect() {
14
15
  try {
15
16
  const conn = await rabbit.connect(this.url);
16
17
  conn.on("error", async (error) => {
@@ -18,10 +19,10 @@ class Broker {
18
19
  });
19
20
 
20
21
  this.channel = await conn.createChannel();
21
- onConnect(this);
22
+ this.onConnect(this);
22
23
  } catch (e) {
23
24
  console.log(`RabbitMQ connect(): ${e.message}`);
24
- setTimeout(this.connect.call(this, { onConnect }), 5000);
25
+ setTimeout(this.connect.bind(this), 5000);
25
26
  }
26
27
  }
27
28
 
@@ -32,6 +33,7 @@ class Broker {
32
33
  else this.channel.ackAll();
33
34
  } catch (e) {
34
35
  console.log(`RabbitMQ acknowledge(): ${e.message}`);
36
+ this.connect()
35
37
  }
36
38
  }
37
39
 
@@ -42,6 +44,7 @@ class Broker {
42
44
  else this.channel.nackAll();
43
45
  } catch (e) {
44
46
  console.log(`RabbitMQ requeue(): ${e.message}`);
47
+ this.connect()
45
48
  }
46
49
  }
47
50
 
@@ -51,6 +54,7 @@ class Broker {
51
54
  await this.channel.recover();
52
55
  } catch (e) {
53
56
  console.log(`RabbitMQ recover(): ${e.message}`);
57
+ this.connect()
54
58
  }
55
59
  }
56
60
 
@@ -65,6 +69,7 @@ class Broker {
65
69
  });
66
70
  } catch (e) {
67
71
  console.log(`RabbitMQ publish(): ${e.message}`);
72
+ this.connect()
68
73
  }
69
74
  }
70
75
 
@@ -75,6 +80,7 @@ class Broker {
75
80
  this.channel.consume(queue_name, handler);
76
81
  } catch (e) {
77
82
  console.log(`RabbitMQ subscribe(): ${e.message}`);
83
+ this.connect()
78
84
  }
79
85
  }
80
86
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@go-mailer/vertebra",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
4
4
  "description": "Go-Mailer vertebra",
5
5
  "main": "index.js",
6
6
  "scripts": {