@quatrain/queue-amqp 1.2.6 → 1.2.7
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/lib/AmqpQueueAdapter.js +10 -3
- package/package.json +1 -1
package/lib/AmqpQueueAdapter.js
CHANGED
|
@@ -58,21 +58,28 @@ class AmqpQueueAdapter extends queue_1.AbstractQueueAdapter {
|
|
|
58
58
|
let concurrents = 0;
|
|
59
59
|
yield this._connect();
|
|
60
60
|
const channel = yield ((_a = this._client) === null || _a === void 0 ? void 0 : _a.createChannel());
|
|
61
|
+
yield (channel === null || channel === void 0 ? void 0 : channel.prefetch(1)); // only get one message at a time
|
|
61
62
|
yield (channel === null || channel === void 0 ? void 0 : channel.assertQueue(topic));
|
|
62
63
|
return channel === null || channel === void 0 ? void 0 : channel.consume(topic, (message) => __awaiter(this, void 0, void 0, function* () {
|
|
63
64
|
concurrents++;
|
|
64
65
|
queue_1.Queue.info(`Concurrent job #${concurrents} of ${concurrency > 0 ? concurrency : 'unlimited'} triggered`);
|
|
65
|
-
channel
|
|
66
|
+
//channel?.ack(message)
|
|
66
67
|
if (concurrency > 0 && concurrents >= concurrency) {
|
|
67
68
|
queue_1.Queue.info(`Reached max concurrency of ${concurrency}, disconnecting from queue`);
|
|
68
69
|
yield this._disconnect();
|
|
69
70
|
}
|
|
70
|
-
|
|
71
|
+
try {
|
|
72
|
+
yield messageHandler(message.content.toString(), params);
|
|
73
|
+
}
|
|
74
|
+
catch (err) {
|
|
75
|
+
queue_1.Queue.error(`messageHandler function failed with message: ${err.message}`);
|
|
76
|
+
}
|
|
71
77
|
if (concurrency > 0 && concurrents >= concurrency) {
|
|
72
78
|
queue_1.Queue.info(`Reached max concurrency of ${concurrency}, exiting gracefully`);
|
|
73
79
|
process.exit();
|
|
74
80
|
}
|
|
75
|
-
})
|
|
81
|
+
}), { noAck: true } // auto-hack
|
|
82
|
+
);
|
|
76
83
|
});
|
|
77
84
|
}
|
|
78
85
|
}
|