@quatrain/queue-amqp 1.1.6

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.
@@ -0,0 +1,6 @@
1
+ import { AbstractQueueAdapter, QueueParameters } from '@quatrain/queue';
2
+ export declare class AmqpQueueAdapter extends AbstractQueueAdapter {
3
+ constructor(params: QueueParameters);
4
+ send(data: any, topic: string): Promise<string>;
5
+ listen(topic: string): Promise<any>;
6
+ }
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.AmqpQueueAdapter = void 0;
13
+ const core_1 = require("@quatrain/core");
14
+ const queue_1 = require("@quatrain/queue");
15
+ const amqp_client_1 = require("@cloudamqp/amqp-client");
16
+ class AmqpQueueAdapter extends queue_1.AbstractQueueAdapter {
17
+ constructor(params) {
18
+ super(params);
19
+ const { url = 'localhost', user, password, port = 5672 } = params.config;
20
+ this._client = new amqp_client_1.AMQPClient(`amqp://${url}:${port}`);
21
+ }
22
+ send(data, topic) {
23
+ return __awaiter(this, void 0, void 0, function* () {
24
+ const conn = yield this._client.connect();
25
+ const ch = yield conn.channel();
26
+ const q = yield ch.queue();
27
+ const dataBuffer = Buffer.from(JSON.stringify(data));
28
+ const messageId = yield q.publish(dataBuffer, { deliveryMode: 2 });
29
+ core_1.Core.log(`[AMQP] Sending message to ${topic}`);
30
+ return messageId;
31
+ });
32
+ }
33
+ listen(topic) {
34
+ 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 });
39
+ });
40
+ }
41
+ }
42
+ exports.AmqpQueueAdapter = AmqpQueueAdapter;
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@quatrain/queue-amqp",
3
+ "version": "1.1.6",
4
+ "description": "Queue adapter for AMQP compatible queue",
5
+ "main": "lib/index.js",
6
+ "types": "lib/index.d.ts",
7
+ "files": [
8
+ "lib/",
9
+ "README.md"
10
+ ],
11
+ "author": "Quatrain Développement SAS <developers@quatrain.com>",
12
+ "license": "MIT",
13
+ "devDependencies": {
14
+ "@tsconfig/recommended": "^1.0.1",
15
+ "@types/fs-extra": "^11.0.4",
16
+ "@types/jest": "^27.0.3",
17
+ "@types/node": "^22.10.1",
18
+ "@types/object-hash": "^3.0.6",
19
+ "jest": "^27.4.7",
20
+ "jest-node-exports-resolver": "^1.1.6",
21
+ "trace-unhandled": "^2.0.1",
22
+ "ts-jest": "^27.1.2",
23
+ "ts-node": "^10.4.0",
24
+ "typescript": "^5.1.5"
25
+ },
26
+ "dependencies": {
27
+ "@cloudamqp/amqp-client": "^3.1.1",
28
+ "@quatrain/core": "^1.1.6",
29
+ "@quatrain/queue": "^1.1.6"
30
+ },
31
+ "scripts": {
32
+ "test": "tsc && jest --verbose",
33
+ "build": "tsc",
34
+ "wbuild": "tsc --watch",
35
+ "bump-to": "yarn version",
36
+ "publish": "yarn build && yarn npm publish --access public"
37
+ }
38
+ }