@quatrain/queue-amqp 1.1.12 → 1.1.14

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,5 +2,5 @@ import { AbstractQueueAdapter, QueueParameters } from '@quatrain/queue';
2
2
  export declare class AmqpQueueAdapter extends AbstractQueueAdapter {
3
3
  constructor(params: QueueParameters);
4
4
  send(data: any, topic: string): Promise<string>;
5
- listen(topic: string): Promise<any>;
5
+ listen(topic: string | undefined, messageHandler: Function): Promise<any>;
6
6
  }
@@ -10,7 +10,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.AmqpQueueAdapter = void 0;
13
- const core_1 = require("@quatrain/core");
14
13
  const queue_1 = require("@quatrain/queue");
15
14
  const amqp_client_1 = require("@cloudamqp/amqp-client");
16
15
  class AmqpQueueAdapter extends queue_1.AbstractQueueAdapter {
@@ -26,16 +25,19 @@ class AmqpQueueAdapter extends queue_1.AbstractQueueAdapter {
26
25
  const q = yield ch.queue();
27
26
  const dataBuffer = Buffer.from(JSON.stringify(data));
28
27
  const messageId = yield q.publish(dataBuffer, { deliveryMode: 2 });
29
- core_1.Core.log(`[AMQP] Sending message to ${topic}`);
28
+ queue_1.Queue.log(`[AMQP] Sending message to ${topic}`);
30
29
  return messageId;
31
30
  });
32
31
  }
33
- listen(topic) {
32
+ listen(topic = this._params.topic, messageHandler) {
34
33
  return __awaiter(this, void 0, void 0, function* () {
35
- const conn = yield this._client.connect();
36
- const ch = yield conn.channel();
37
- const q = yield ch.queue();
38
- return q.subscribe({ noAck: true });
34
+ if (!topic) {
35
+ throw new Error(`No topic provided for listening.`);
36
+ }
37
+ const connection = yield this._client.connect();
38
+ const channel = yield connection.channel();
39
+ const queue = yield channel.queue(topic);
40
+ return queue.subscribe({ noAck: true }, (message) => __awaiter(this, void 0, void 0, function* () { return yield messageHandler(message); }));
39
41
  });
40
42
  }
41
43
  }
package/lib/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ import { AmqpQueueAdapter } from './AmqpQueueAdapter';
2
+ export { AmqpQueueAdapter };
package/lib/index.js ADDED
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AmqpQueueAdapter = void 0;
4
+ const AmqpQueueAdapter_1 = require("./AmqpQueueAdapter");
5
+ Object.defineProperty(exports, "AmqpQueueAdapter", { enumerable: true, get: function () { return AmqpQueueAdapter_1.AmqpQueueAdapter; } });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quatrain/queue-amqp",
3
- "version": "1.1.12",
3
+ "version": "1.1.14",
4
4
  "description": "Queue adapter for AMQP compatible queue",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -25,8 +25,8 @@
25
25
  },
26
26
  "dependencies": {
27
27
  "@cloudamqp/amqp-client": "^3.1.1",
28
- "@quatrain/core": "^1.1.15",
29
- "@quatrain/queue": "^1.1.12"
28
+ "@quatrain/core": "^1.1.18",
29
+ "@quatrain/queue": "^1.1.13"
30
30
  },
31
31
  "scripts": {
32
32
  "test-ci": "jest --runInBand",