amqplib 1.1.0 → 1.1.1
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/CHANGELOG.md +3 -0
- package/lib/recovery.js +6 -1
- package/package.json +1 -1
- package/test/recovery.test.js +32 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
# Change log for amqplib
|
|
2
2
|
|
|
3
|
+
## v1.1.1
|
|
4
|
+
- Forward `handler-error` events from the underlying connection to the recovery wrapper, so listeners attached to `RecoveringPromiseModel`/`RecoveringCallbackModel` receive handler errors
|
|
5
|
+
|
|
3
6
|
## v1.1.0
|
|
4
7
|
- Add connection recovery via `connectWithRecoveryPromise` and `connectWithRecoveryCallback` — automatically reconnects on connection loss with configurable backoff delay, jitter, and retry limits (thanks [@ShiriNmi1520](https://github.com/ShiriNmi1520))
|
|
5
8
|
|
package/lib/recovery.js
CHANGED
|
@@ -220,12 +220,14 @@ class RecoveringCore extends EventEmitter {
|
|
|
220
220
|
const onUnblocked = () => this.emit('unblocked');
|
|
221
221
|
const onConnectionError = (err) => this.emit('error', err);
|
|
222
222
|
const onUpdateSecretOk = () => this.emit('update-secret-ok');
|
|
223
|
+
const onHandlerError = (err, event) => this.emit('handler-error', err, event);
|
|
223
224
|
|
|
224
225
|
model.on('close', onClose);
|
|
225
226
|
model.on('blocked', onBlocked);
|
|
226
227
|
model.on('unblocked', onUnblocked);
|
|
227
228
|
model.on('error', onConnectionError);
|
|
228
229
|
model.on('update-secret-ok', onUpdateSecretOk);
|
|
230
|
+
model.on('handler-error', onHandlerError);
|
|
229
231
|
|
|
230
232
|
this._modelListeners = {
|
|
231
233
|
model,
|
|
@@ -234,17 +236,19 @@ class RecoveringCore extends EventEmitter {
|
|
|
234
236
|
onUnblocked,
|
|
235
237
|
onConnectionError,
|
|
236
238
|
onUpdateSecretOk,
|
|
239
|
+
onHandlerError,
|
|
237
240
|
};
|
|
238
241
|
}
|
|
239
242
|
|
|
240
243
|
_unbindModel() {
|
|
241
244
|
if (!this._modelListeners) return;
|
|
242
|
-
const { model, onClose, onBlocked, onUnblocked, onConnectionError, onUpdateSecretOk } = this._modelListeners;
|
|
245
|
+
const { model, onClose, onBlocked, onUnblocked, onConnectionError, onUpdateSecretOk, onHandlerError } = this._modelListeners;
|
|
243
246
|
model.removeListener('close', onClose);
|
|
244
247
|
model.removeListener('blocked', onBlocked);
|
|
245
248
|
model.removeListener('unblocked', onUnblocked);
|
|
246
249
|
model.removeListener('error', onConnectionError);
|
|
247
250
|
model.removeListener('update-secret-ok', onUpdateSecretOk);
|
|
251
|
+
model.removeListener('handler-error', onHandlerError);
|
|
248
252
|
model.on('error', () => {});
|
|
249
253
|
this._modelListeners = null;
|
|
250
254
|
}
|
|
@@ -366,6 +370,7 @@ function wireCommonEvents(source, target) {
|
|
|
366
370
|
'unblocked',
|
|
367
371
|
'error',
|
|
368
372
|
'update-secret-ok',
|
|
373
|
+
'handler-error',
|
|
369
374
|
].forEach((eventName) => {
|
|
370
375
|
source.on(eventName, (...args) => target.emit(eventName, ...args));
|
|
371
376
|
});
|
package/package.json
CHANGED
package/test/recovery.test.js
CHANGED
|
@@ -167,6 +167,38 @@ describe('recovery', () => {
|
|
|
167
167
|
assert(client);
|
|
168
168
|
});
|
|
169
169
|
|
|
170
|
+
it('handler-error from underlying model is forwarded to recovery wrapper', async () => {
|
|
171
|
+
const models = [];
|
|
172
|
+
let opened = 0;
|
|
173
|
+
|
|
174
|
+
function openModel() {
|
|
175
|
+
const model = new FakePromiseModel(++opened);
|
|
176
|
+
models.push(model);
|
|
177
|
+
return Promise.resolve(model);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const client = await recovery.connectWithRecoveryPromise(openModel, {
|
|
181
|
+
initialDelay: 1,
|
|
182
|
+
maxDelay: 1,
|
|
183
|
+
jitter: 0,
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
const expectedErr = new Error('user close handler explodes');
|
|
187
|
+
|
|
188
|
+
await new Promise((resolve) => {
|
|
189
|
+
client.on('handler-error', (err, event) => {
|
|
190
|
+
assert.strictEqual(err, expectedErr);
|
|
191
|
+
assert.strictEqual(event, 'close');
|
|
192
|
+
resolve();
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
// Simulate a handler throwing in a 'close' listener on the underlying model
|
|
196
|
+
models[0].emit('handler-error', expectedErr, 'close');
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
await client.close();
|
|
200
|
+
});
|
|
201
|
+
|
|
170
202
|
it('promise recovery fails after max retries', async () => {
|
|
171
203
|
let attempts = 0;
|
|
172
204
|
|