@azteam/rabbitmq-async 1.0.117 → 1.0.120

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@azteam/rabbitmq-async",
3
- "version": "1.0.117",
3
+ "version": "1.0.120",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "engines": {
@@ -16,7 +16,7 @@
16
16
  "author": "toda <sp.azsolution.net@gmail.com>",
17
17
  "license": "MIT",
18
18
  "dependencies": {
19
- "@azteam/util": "1.0.10",
19
+ "@azteam/util": "1.0.13",
20
20
  "amqplib": "0.8.0"
21
21
  }
22
22
  }
@@ -87,14 +87,15 @@ class RabbitMQAsync {
87
87
  return this.send(queueName, msg);
88
88
  } finally {
89
89
  try {
90
- channel && channel.close();
90
+ if (channel) {
91
+ channel.close();
92
+ }
91
93
  } catch (err) {}
92
94
  }
93
95
  } else {
94
96
  await timeout(5000);
95
97
  return this.send(queueName, msg);
96
98
  }
97
- return false;
98
99
  }
99
100
 
100
101
  async receiving(queueName, cb, callbackError = null) {
@@ -112,8 +113,9 @@ class RabbitMQAsync {
112
113
 
113
114
  const messageQueue = this;
114
115
  channel.consume(prefixQueueName, async function (msg) {
116
+ const data = JSON.parse(msg.content.toString());
117
+
115
118
  try {
116
- const data = JSON.parse(msg.content.toString());
117
119
  if (msg.fields.redelivered) {
118
120
  if (!data.retry) {
119
121
  data.retry = 0;
@@ -134,23 +136,33 @@ class RabbitMQAsync {
134
136
  }
135
137
  await channel.ack(msg);
136
138
  } catch (err) {
137
- await channel.nack(msg);
138
- callbackError && callbackError(prefixQueueName, err);
139
+ if (data.noRetry) {
140
+ await channel.ack(msg);
141
+ } else {
142
+ await channel.nack(msg);
143
+ }
144
+ if (callbackError) {
145
+ callbackError(prefixQueueName, err);
146
+ }
139
147
  }
140
148
  });
141
149
  } catch (err) {
142
150
  try {
143
- channel && channel.close();
144
- // eslint-disable-next-line no-shadow
145
- } catch (err) {}
151
+ if (channel) {
152
+ channel.close();
153
+ }
154
+ } catch (err2) {}
146
155
  await timeout(5000);
147
- callbackError && callbackError(prefixQueueName, err);
156
+ if (callbackError) {
157
+ callbackError(prefixQueueName, err);
158
+ }
148
159
  return this.receiving(queueName, cb, callbackError);
149
160
  }
150
161
  } else {
151
162
  await timeout(5000);
152
163
  return this.receiving(queueName, cb, callbackError);
153
164
  }
165
+ return false;
154
166
  }
155
167
 
156
168
  setAlertCallback(callback) {
@@ -161,7 +173,7 @@ class RabbitMQAsync {
161
173
  if (typeof this.alertCallback === 'function') {
162
174
  this.alertCallback(status, msg);
163
175
  } else {
164
- console.log(status, msg);
176
+ console.info(status, msg);
165
177
  }
166
178
  }
167
179
  }