@quatrain/queue-amqp 1.2.3 → 1.2.5

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.
@@ -5,5 +5,5 @@ export declare class AmqpQueueAdapter extends AbstractQueueAdapter {
5
5
  protected _connect(): Promise<amqplib.ChannelModel | undefined>;
6
6
  protected _disconnect(): Promise<void>;
7
7
  send(data: any, topic: string): Promise<string>;
8
- listen(topic: string | undefined, messageHandler: Function, concurrency?: number): Promise<amqplib.Replies.Consume | undefined>;
8
+ listen(topic: string | undefined, messageHandler: Function, params?: any): Promise<amqplib.Replies.Consume | undefined>;
9
9
  }
@@ -46,26 +46,29 @@ class AmqpQueueAdapter extends queue_1.AbstractQueueAdapter {
46
46
  return String(id);
47
47
  });
48
48
  }
49
- listen(topic = this._params.topic, messageHandler, concurrency = 0) {
49
+ listen(topic = this._params.topic, messageHandler, params) {
50
50
  var _a;
51
51
  return __awaiter(this, void 0, void 0, function* () {
52
52
  if (!topic) {
53
53
  throw new Error(`No topic provided for listening.`);
54
54
  }
55
- let concurrents = 1;
55
+ const concurrency = (params === null || params === void 0 ? void 0 : params.concurrency) || 0;
56
+ queue_1.Queue.info(`Starting to listen to topic ${topic} with max concurrency set to ${concurrency}`);
57
+ let concurrents = 0;
56
58
  yield this._connect();
57
59
  const channel = yield ((_a = this._client) === null || _a === void 0 ? void 0 : _a.createChannel());
58
60
  yield (channel === null || channel === void 0 ? void 0 : channel.assertQueue(topic));
59
61
  return channel === null || channel === void 0 ? void 0 : channel.consume(topic, (message) => __awaiter(this, void 0, void 0, function* () {
60
- // execute workflow
61
- if (concurrency > 0) {
62
- queue_1.Queue.info(`Concurrent job #${concurrents + 1} of ${concurrency} triggered`);
63
- }
64
- yield messageHandler(message.content.toString());
65
- channel === null || channel === void 0 ? void 0 : channel.ack(message);
66
62
  concurrents++;
67
- if (concurrency > 0 && concurrents > concurrency) {
63
+ queue_1.Queue.info(`Concurrent job #${concurrents} of ${concurrency > 0 ? concurrency : 'unlimited'} triggered`);
64
+ channel === null || channel === void 0 ? void 0 : channel.ack(message);
65
+ if (concurrency > 0 && concurrents >= concurrency) {
66
+ queue_1.Queue.info(`Reached max concurrency of ${concurrency}, disconnecting from queue`);
68
67
  yield this._disconnect();
68
+ }
69
+ yield messageHandler(message.content.toString(), params);
70
+ if (concurrency > 0 && concurrents >= concurrency) {
71
+ queue_1.Queue.info(`Reached max concurrency of ${concurrency}, exiting gracefully`);
69
72
  process.exit();
70
73
  }
71
74
  }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quatrain/queue-amqp",
3
- "version": "1.2.3",
3
+ "version": "1.2.5",
4
4
  "description": "Queue adapter for AMQP compatible queue",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -27,7 +27,7 @@
27
27
  "dependencies": {
28
28
  "@cloudamqp/amqp-client": "^3.4.1",
29
29
  "@quatrain/core": "^1.1.22",
30
- "@quatrain/queue": "^1.1.17",
30
+ "@quatrain/queue": "^1.1.18",
31
31
  "amqplib": "^0.10.9"
32
32
  },
33
33
  "scripts": {