@azteam/rabbitmq-async 1.0.109 → 1.0.112

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/package.json CHANGED
@@ -1,12 +1,8 @@
1
1
  {
2
2
  "name": "@azteam/rabbitmq-async",
3
- "version": "1.0.109",
3
+ "version": "1.0.112",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
- "repository": {
7
- "type": "git",
8
- "url": "git+https://github.com/toda93/rabbitmq-async.git"
9
- },
10
6
  "engines": {
11
7
  "node": ">= 12.0.0",
12
8
  "npm": ">=7.0.0"
@@ -19,12 +15,8 @@
19
15
  ],
20
16
  "author": "toda <sp.azsolution.net@gmail.com>",
21
17
  "license": "MIT",
22
- "bugs": {
23
- "url": "https://github.com/toda93/rabbitmq-async/issues"
24
- },
25
- "homepage": "https://github.com/toda93/rabbitmq-async#readme",
26
18
  "dependencies": {
27
- "@azteam/util": "1.0.8",
19
+ "@azteam/util": "1.0.9",
28
20
  "amqplib": "0.8.0"
29
21
  }
30
22
  }
package/src/Provider.js CHANGED
@@ -1,13 +1,15 @@
1
1
  import RabbitMQAsync from './RabbitMQAsync';
2
2
 
3
3
  class Provider {
4
- constructor(configs, isSingle = false) {
4
+ constructor(configs = []) {
5
5
  this.connections = {};
6
- this.configs = configs;
7
- if (isSingle) {
8
- this.configs = {
9
- single: configs,
10
- };
6
+ if (Array.isArray(configs)) {
7
+ configs.map((config) => {
8
+ this.configs[config.name] = config;
9
+ return true;
10
+ });
11
+ } else {
12
+ this.configs.single = configs;
11
13
  }
12
14
  }
13
15
 
@@ -13,15 +13,12 @@ class RabbitMQAsync {
13
13
  }
14
14
 
15
15
  async waitConnection(n = 10) {
16
- let i = 0;
17
- while (!this.connected) {
18
- ++i;
19
- if (i >= n) {
20
- return false;
21
- }
16
+ for (let i = 0; !this.connected || i < n; i += 1) {
22
17
  await timeout(1000);
23
18
  }
24
- return true;
19
+ if (!this.connected) {
20
+ throw new Error('Rabbit not connected');
21
+ }
25
22
  }
26
23
 
27
24
  async connect() {
@@ -34,7 +31,7 @@ class RabbitMQAsync {
34
31
 
35
32
  this.client.on('error', (err) => {
36
33
  this.connected = false;
37
- this._alert('error', 'MQ Error' + err);
34
+ this._alert('error', `MQ Error${err}`);
38
35
  this.reconnect();
39
36
  });
40
37
 
@@ -45,7 +42,7 @@ class RabbitMQAsync {
45
42
  });
46
43
  } catch (err) {
47
44
  this.connected = false;
48
- this._alert('error', 'MQ connect' + err);
45
+ this._alert('error', `MQ connect${err}`);
49
46
  this.reconnect();
50
47
  }
51
48
  }