@quatrain/queue-amqp 1.2.20 → 1.2.22

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.
@@ -2,6 +2,8 @@ import { AbstractQueueAdapter } from '@quatrain/queue';
2
2
  import amqplib, { ChannelModel } from 'amqplib';
3
3
  export declare class AmqpQueueAdapter extends AbstractQueueAdapter {
4
4
  protected _client: ChannelModel | undefined;
5
+ protected _logger: any;
6
+ constructor(params: any);
5
7
  protected _connect(): Promise<ChannelModel>;
6
8
  protected _disconnect(): Promise<void>;
7
9
  send(data: any, topic: string): Promise<string>;
@@ -16,6 +16,10 @@ exports.AmqpQueueAdapter = void 0;
16
16
  const queue_1 = require("@quatrain/queue");
17
17
  const amqplib_1 = __importDefault(require("amqplib"));
18
18
  class AmqpQueueAdapter extends queue_1.AbstractQueueAdapter {
19
+ constructor(params) {
20
+ super(params);
21
+ this._logger = queue_1.Queue.logger.clone('AMQP');
22
+ }
19
23
  _connect() {
20
24
  return __awaiter(this, void 0, void 0, function* () {
21
25
  if (!this._client) {
@@ -37,11 +41,11 @@ class AmqpQueueAdapter extends queue_1.AbstractQueueAdapter {
37
41
  yield this._connect();
38
42
  const channel = yield ((_a = this._client) === null || _a === void 0 ? void 0 : _a.createChannel());
39
43
  const dataBuffer = Buffer.from(JSON.stringify(data));
40
- queue_1.Queue.info(`[AMQP] Sending message to ${topic}`);
44
+ this._logger.info(`Sending message to ${topic}`);
41
45
  channel === null || channel === void 0 ? void 0 : channel.sendToQueue(topic, dataBuffer);
42
46
  channel === null || channel === void 0 ? void 0 : channel.close();
43
47
  const id = Date.now(); // fake
44
- queue_1.Queue.info(`[AMQP] Message send with id ${id}`);
48
+ this._logger.info(`Message send with id ${id}`);
45
49
  return String(id);
46
50
  });
47
51
  }
@@ -58,7 +62,7 @@ class AmqpQueueAdapter extends queue_1.AbstractQueueAdapter {
58
62
  throw new Error(`No topic provided for listening.`);
59
63
  }
60
64
  const concurrency = (params === null || params === void 0 ? void 0 : params.concurrency) || 0;
61
- queue_1.Queue.info(`Starting to listen to topic ${topic} with max concurrency set to ${concurrency}`);
65
+ this._logger.info(`Starting to listen to topic ${topic} with max concurrency set to ${concurrency}`);
62
66
  let concurrents = 0;
63
67
  const client = yield this._connect();
64
68
  const channel = yield client.createChannel();
@@ -69,7 +73,7 @@ class AmqpQueueAdapter extends queue_1.AbstractQueueAdapter {
69
73
  return;
70
74
  }
71
75
  concurrents++;
72
- queue_1.Queue.info(`Job #${concurrents} of ${concurrency > 0 ? concurrency : 'unlimited'} started`);
76
+ this._logger.info(`Job #${concurrents} of ${concurrency > 0 ? concurrency : 'unlimited'} started`);
73
77
  try {
74
78
  // 1. Process the message synchronously (wait for it to finish)
75
79
  const result = yield messageHandler(msg.content.toString(), params);
@@ -80,14 +84,14 @@ class AmqpQueueAdapter extends queue_1.AbstractQueueAdapter {
80
84
  channel.ack(msg);
81
85
  // 3. Check if we reached the limit of messages to process
82
86
  if (concurrency > 0 && concurrents >= concurrency) {
83
- queue_1.Queue.info(`Reached max concurrency of ${concurrency}, disconnecting from queue`);
87
+ this._logger.info(`Reached max concurrency of ${concurrency}, disconnecting from queue`);
84
88
  yield channel.close();
85
89
  yield client.close();
86
90
  process.exit(0);
87
91
  }
88
92
  }
89
93
  catch (err) {
90
- queue_1.Queue.error(`messageHandler function failed with message: ${err.message}`);
94
+ this._logger.error(`messageHandler function failed with message: ${err.message}`);
91
95
  // Negative acknowledge the message so it can be requeued or handled by DLQ
92
96
  channel.nack(msg);
93
97
  process.exit(1);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quatrain/queue-amqp",
3
- "version": "1.2.20",
3
+ "version": "1.2.22",
4
4
  "description": "Queue adapter for AMQP compatible queue",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -30,7 +30,7 @@
30
30
  "dependencies": {
31
31
  "@cloudamqp/amqp-client": "^3.4.1",
32
32
  "@quatrain/core": "^1.1.48",
33
- "@quatrain/queue": "^1.1.27",
33
+ "@quatrain/queue": "^1.1.28",
34
34
  "amqplib": "^0.10.9"
35
35
  },
36
36
  "scripts": {
@@ -3,6 +3,12 @@ import amqplib, { ChannelModel, ConsumeMessage, Message } from 'amqplib'
3
3
 
4
4
  export class AmqpQueueAdapter extends AbstractQueueAdapter {
5
5
  protected _client: ChannelModel | undefined
6
+ protected _logger: any
7
+
8
+ constructor(params: any) {
9
+ super(params)
10
+ this._logger = (Queue as any).logger.clone('AMQP')
11
+ }
6
12
 
7
13
  protected async _connect(): Promise<ChannelModel> {
8
14
  if (!this._client) {
@@ -31,13 +37,13 @@ export class AmqpQueueAdapter extends AbstractQueueAdapter {
31
37
  const channel = await this._client?.createChannel()
32
38
 
33
39
  const dataBuffer = Buffer.from(JSON.stringify(data))
34
- Queue.info(`[AMQP] Sending message to ${topic}`)
40
+ this._logger.info(`Sending message to ${topic}`)
35
41
 
36
42
  channel?.sendToQueue(topic, dataBuffer)
37
43
  channel?.close()
38
44
 
39
45
  const id = Date.now() // fake
40
- Queue.info(`[AMQP] Message send with id ${id}`)
46
+ this._logger.info(`Message send with id ${id}`)
41
47
 
42
48
  return String(id)
43
49
  }
@@ -60,7 +66,7 @@ export class AmqpQueueAdapter extends AbstractQueueAdapter {
60
66
 
61
67
  const concurrency = params?.concurrency || 0
62
68
 
63
- Queue.info(
69
+ this._logger.info(
64
70
  `Starting to listen to topic ${topic} with max concurrency set to ${concurrency}`
65
71
  )
66
72
 
@@ -79,7 +85,7 @@ export class AmqpQueueAdapter extends AbstractQueueAdapter {
79
85
  }
80
86
 
81
87
  concurrents++
82
- Queue.info(
88
+ this._logger.info(
83
89
  `Job #${concurrents} of ${
84
90
  concurrency > 0 ? concurrency : 'unlimited'
85
91
  } started`
@@ -103,7 +109,7 @@ export class AmqpQueueAdapter extends AbstractQueueAdapter {
103
109
 
104
110
  // 3. Check if we reached the limit of messages to process
105
111
  if (concurrency > 0 && concurrents >= concurrency) {
106
- Queue.info(
112
+ this._logger.info(
107
113
  `Reached max concurrency of ${concurrency}, disconnecting from queue`
108
114
  )
109
115
  await channel.close()
@@ -111,7 +117,7 @@ export class AmqpQueueAdapter extends AbstractQueueAdapter {
111
117
  process.exit(0)
112
118
  }
113
119
  } catch (err) {
114
- Queue.error(
120
+ this._logger.error(
115
121
  `messageHandler function failed with message: ${
116
122
  (err as Error).message
117
123
  }`