@quatrain/queue-amqp 1.2.3 → 1.2.4

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,12 +46,14 @@ 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
+ 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}`);
55
57
  let concurrents = 1;
56
58
  yield this._connect();
57
59
  const channel = yield ((_a = this._client) === null || _a === void 0 ? void 0 : _a.createChannel());
@@ -61,10 +63,11 @@ class AmqpQueueAdapter extends queue_1.AbstractQueueAdapter {
61
63
  if (concurrency > 0) {
62
64
  queue_1.Queue.info(`Concurrent job #${concurrents + 1} of ${concurrency} triggered`);
63
65
  }
64
- yield messageHandler(message.content.toString());
66
+ yield messageHandler(message.content.toString(), params);
65
67
  channel === null || channel === void 0 ? void 0 : channel.ack(message);
66
68
  concurrents++;
67
69
  if (concurrency > 0 && concurrents > concurrency) {
70
+ queue_1.Queue.info(`Reached max concurrencu of ${concurrency}, exiting gracefully`);
68
71
  yield this._disconnect();
69
72
  process.exit();
70
73
  }
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.4",
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": {