Skip to content

Commit 32d5def

Browse files
Feature/routing keys (#29) (#30)
* add custom routing key option * bump version --------- Co-authored-by: Santiago Sanchez <ssd170@gmail.com>
1 parent aa28831 commit 32d5def

File tree

8 files changed

+1984
-12482
lines changed

8 files changed

+1984
-12482
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
node_modules
22
/lib
33
/coverage
4+
.vscode
5+
.idea

package-lock.json

Lines changed: 1944 additions & 12405 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
22
"name": "q-wrapper",
3-
"version": "1.0.4",
3+
"version": "1.0.8",
44
"description": "A TypeScript npm package that manages queue connections and operations with amqplib.",
55
"main": "lib/index.js",
66
"types": "lib/index.d.ts",
77
"scripts": {
88
"test": "jest --config jestconfig.json",
9-
"build": "tsc -d --declarationDir lib",
9+
"build": "tsc --build",
1010
"build:watch": "tsc --watch",
1111
"format": "prettier --write \"src/**/*.ts\" \"src/**/*.js\"",
1212
"lint": "tslint -p tsconfig.json",
@@ -30,17 +30,17 @@
3030
"author": "sanchez@acrontum.de",
3131
"license": "MIT",
3232
"devDependencies": {
33-
"@types/amqplib": "^0.8.2",
34-
"@types/jest": "^25.1.2",
35-
"jest": "^25.1.0",
33+
"@types/amqplib": "^0.10.1",
34+
"@types/jest": "^29.4.0",
35+
"jest": "^29.4.2",
3636
"prettier": "^1.19.1",
37-
"ts-jest": "^25.2.1",
38-
"tslint": "^6.0.0",
37+
"ts-jest": "^29.0.5",
38+
"tslint": "^6.1.3",
3939
"tslint-config-prettier": "^1.18.0",
40-
"typescript": "^3.7.5"
40+
"typescript": "^4.3.5"
4141
},
4242
"dependencies": {
43-
"amqplib": "^0.8.0"
43+
"amqplib": "^0.10.3"
4444
},
4545
"files": [
4646
"lib/**/*"

src/__tests__/QWrapperDomain.test.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,27 @@
11
import { QWrapperDomain, QWrapperSettings } from '..';
2+
import { ExchangeType } from '../models/QWrapperSettings';
23

34
const settings: QWrapperSettings = {
4-
exchange: 'test_dsd_exchange',
5+
exchange: 'amq.fanout',
56
connection: {
67
protocol: 'amqp',
78
hostname: 'localhost',
89
port: 5672,
9-
username: 'guest',
10-
password: 'guest',
11-
locale: 'en_US',
12-
frameMax: 0,
13-
heartbeat: 0,
14-
vhost: '/',
10+
username: 'admin',
11+
password: 'admin',
12+
vhost: 'vhost',
1513
},
16-
queue: 'test_dsd_queue',
17-
exchangeType: 'fanout',
14+
queue: 'myqueue.events',
15+
exchangeType: ExchangeType.fanout,
1816
reconnect: false,
19-
dleExchange: 'test_dsd_dead_exchange',
20-
dleQueue: 'test_dsd_dead_letter',
17+
dleExchange: 'amq.fanout',
18+
dleQueue: 'myqueue.dle_events',
2119
};
2220

2321
test('Queue manager constructor string url', done => {
2422
const qw = new QWrapperDomain({
2523
...settings,
26-
connection: 'amqp://localhost',
24+
connection: 'amqp://admin:admin@localhost:5672/vhost',
2725
});
2826
done();
2927
});

src/demo.ts

Lines changed: 0 additions & 46 deletions
This file was deleted.

src/domains/QWrapperDomain.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ export class QWrapperDomain {
9191
});
9292
console.info(`${packageName} Queue: '${this._settings.queue}' asserted successfully`);
9393

94-
this._channel.bindQueue(this._settings.queue, this._settings.exchange, this._settings.queue);
94+
const routingKey = this._settings.routingKey ? this._settings.routingKey : this._settings.queue;
95+
this._channel.bindQueue(this._settings.queue, this._settings.exchange, routingKey);
9596

9697
this._channel.prefetch(this._settings.prefetch || 1);
9798

src/models/QWrapperSettings.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
import { ConnectionOptions } from './ConnectionOptions';
22

3+
export enum ExchangeType {
4+
direct = 'direct',
5+
topic = 'topic',
6+
fanout = 'fanout',
7+
}
8+
39
export interface QWrapperSettings {
410
connection: string | ConnectionOptions;
5-
queue: string;
11+
dleExchange?: string;
12+
dleQueue: string;
613
exchange: string;
7-
exchangeType: string;
14+
exchangeType: ExchangeType | string;
15+
prefetch?: number;
16+
queue: string;
17+
reconnect?: boolean;
18+
routingKey?: string;
819
verboseLogging?: boolean;
920
veryVerboseLogging?: boolean;
10-
reconnect?: boolean;
11-
prefetch?: number;
12-
dleQueue: string;
13-
dleExchange?: string;
1421
}

tsconfig.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
{
22
"compilerOptions": {
3-
"target": "ES2018",
4-
"module": "commonjs",
53
"declaration": true,
4+
"module": "commonjs",
65
"outDir": "./lib",
7-
"strict": true
6+
"rootDir": "src",
7+
"strict": true,
8+
"target": "ES2020",
89
},
910
"include": ["src"],
1011
"exclude": [

0 commit comments

Comments
 (0)