@azteam/rabbitmq-async 1.0.125 → 1.0.136

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.125",
3
+ "version": "1.0.136",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "engines": {
@@ -17,6 +17,6 @@
17
17
  "license": "MIT",
18
18
  "dependencies": {
19
19
  "@azteam/util": "1.0.13",
20
- "amqplib": "0.10.1"
20
+ "amqplib": "0.8.0"
21
21
  }
22
22
  }
@@ -68,7 +68,7 @@ class RabbitMQAsync {
68
68
  const prefixQueueName = this.parsePrefix(queueName);
69
69
 
70
70
  if (this.connected) {
71
- let channel = null;
71
+ let channel;
72
72
  try {
73
73
  channel = await this.client.createChannel();
74
74
  const queueInfo = await channel.assertQueue(prefixQueueName, {
@@ -87,9 +87,7 @@ class RabbitMQAsync {
87
87
  return this.send(queueName, msg);
88
88
  } finally {
89
89
  try {
90
- if (channel) {
91
- channel.close();
92
- }
90
+ await channel.close();
93
91
  } catch (err) {}
94
92
  }
95
93
  } else {
@@ -102,21 +100,17 @@ class RabbitMQAsync {
102
100
  const prefixQueueName = this.parsePrefix(queueName);
103
101
 
104
102
  if (this.connected) {
105
- let channel = null;
103
+ let channel;
106
104
  try {
107
105
  channel = await this.client.createChannel();
108
- const queueInfo = await channel.assertQueue(prefixQueueName, {
106
+ return await channel.assertQueue(prefixQueueName, {
109
107
  durable: true,
110
108
  });
111
-
112
- return queueInfo;
113
109
  } catch (err) {
114
110
  return this.getInfo(queueName);
115
111
  } finally {
116
112
  try {
117
- if (channel) {
118
- channel.close();
119
- }
113
+ await channel.close();
120
114
  } catch (err) {}
121
115
  }
122
116
  } else {
@@ -128,7 +122,7 @@ class RabbitMQAsync {
128
122
  const prefixQueueName = this.parsePrefix(queueName);
129
123
 
130
124
  if (this.connected) {
131
- let channel = null;
125
+ let channel;
132
126
  try {
133
127
  channel = await this.client.createChannel();
134
128
 
@@ -142,62 +136,60 @@ class RabbitMQAsync {
142
136
 
143
137
  await new Promise((resolve, reject) => {
144
138
  channel.consume(prefixQueueName, async function (msg) {
145
- const data = JSON.parse(msg.content.toString());
146
-
147
- try {
148
- if (msg.fields.redelivered) {
149
- if (!data.retry) {
150
- data.retry = 0;
151
- }
152
- data.retry += 1;
139
+ if (msg !== null) {
140
+ const data = JSON.parse(msg.content.toString());
141
+ try {
142
+ if (msg.fields.redelivered) {
143
+ if (!data.retry) {
144
+ data.retry = 0;
145
+ }
146
+ data.retry += 1;
153
147
 
154
- if (data.retry < 5) {
155
- await messageQueue.send(queueName, data);
156
- } else {
157
- await messageQueue.send(messageQueue.parsePrefix('RETRY'), {
158
- queueName,
159
- data,
160
- retry_time: new Date(),
161
- });
162
- }
163
- await channel.ack(msg);
164
- } else {
165
- try {
166
- await cb(data);
167
- await channel.ack(msg);
168
- } catch (err) {
169
- if (callbackError) {
170
- callbackError(prefixQueueName, err);
148
+ if (data.retry < 5) {
149
+ await messageQueue.send(queueName, data);
150
+ } else {
151
+ await messageQueue.send(messageQueue.parsePrefix('RETRY'), {
152
+ queueName,
153
+ data,
154
+ retry_time: new Date(),
155
+ });
171
156
  }
172
- if (data.noRetry) {
157
+ await channel.ack(msg);
158
+ } else {
159
+ try {
160
+ await cb(data);
173
161
  await channel.ack(msg);
174
- } else {
175
- await channel.nack(msg);
162
+ } catch (err) {
163
+ if (callbackError) {
164
+ callbackError(prefixQueueName, err);
165
+ }
166
+ if (data.noRetry) {
167
+ await channel.ack(msg);
168
+ } else {
169
+ await channel.nack(msg);
170
+ }
176
171
  }
177
172
  }
173
+ } catch (err) {
174
+ reject(err);
178
175
  }
179
- } catch (err) {
180
- reject(err);
176
+ } else {
177
+ throw new Error('msg null');
181
178
  }
182
179
  });
183
180
  });
184
181
  } catch (err) {
185
182
  try {
186
- if (channel) {
187
- channel.close();
188
- }
183
+ await channel.close();
189
184
  } catch (err2) {}
185
+
190
186
  await timeout(5000);
191
- if (callbackError) {
192
- callbackError(prefixQueueName, err);
193
- }
194
187
  return this.receiving(queueName, cb, callbackError);
195
188
  }
196
189
  } else {
197
190
  await timeout(5000);
198
191
  return this.receiving(queueName, cb, callbackError);
199
192
  }
200
- return false;
201
193
  }
202
194
 
203
195
  setAlertCallback(callback) {