amqp-extension 0.0.5 → 1.0.1
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.
- package/.eslintrc +25 -0
- package/README.MD +116 -18
- package/dist/config/type.d.ts +3 -3
- package/dist/config/utils.d.ts +2 -2
- package/dist/config/utils.js +5 -7
- package/dist/config/utils.js.map +1 -1
- package/dist/connection/utils.d.ts +2 -2
- package/dist/connection/utils.js +1 -4
- package/dist/connection/utils.js.map +1 -1
- package/dist/consume/index.d.ts +1 -0
- package/dist/consume/index.js +1 -0
- package/dist/consume/index.js.map +1 -1
- package/dist/consume/static.d.ts +1 -0
- package/dist/consume/static.js +5 -0
- package/dist/consume/static.js.map +1 -0
- package/dist/consume/type.d.ts +6 -4
- package/dist/consume/utils.d.ts +1 -1
- package/dist/consume/utils.js +16 -19
- package/dist/consume/utils.js.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -3
- package/dist/index.js.map +1 -1
- package/dist/message/build.d.ts +1 -1
- package/dist/message/build.js +1 -1
- package/dist/message/build.js.map +1 -1
- package/dist/message/type.d.ts +1 -1
- package/dist/publish/type.d.ts +2 -2
- package/dist/publish/utils.d.ts +2 -2
- package/dist/publish/utils.js.map +1 -1
- package/dist/utils.d.ts +2 -2
- package/dist/utils.js +1 -1
- package/dist/utils.js.map +1 -1
- package/package.json +20 -13
package/.eslintrc
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": [
|
|
3
|
+
"@tada5hi/eslint-config-typescript"
|
|
4
|
+
],
|
|
5
|
+
"parserOptions": {
|
|
6
|
+
"project": "./tsconfig.json"
|
|
7
|
+
},
|
|
8
|
+
"ignorePatterns": ["**/dist/*", "**/*.d.ts", "**/test/*"],
|
|
9
|
+
"globals": {
|
|
10
|
+
"NodeJS": true
|
|
11
|
+
},
|
|
12
|
+
"rules": {
|
|
13
|
+
"class-methods-use-this": "off",
|
|
14
|
+
"import/no-cycle": [2, {
|
|
15
|
+
"maxDepth": 1
|
|
16
|
+
}],
|
|
17
|
+
|
|
18
|
+
"no-continue": "off",
|
|
19
|
+
"no-use-before-define": "off",
|
|
20
|
+
"no-nested-ternary": "off",
|
|
21
|
+
|
|
22
|
+
"@typescript-eslint/no-unused-vars": "off",
|
|
23
|
+
"@typescript-eslint/no-use-before-define": "off"
|
|
24
|
+
}
|
|
25
|
+
}
|
package/README.MD
CHANGED
|
@@ -14,6 +14,7 @@ All utility functions support the usage of multiple registered connections.
|
|
|
14
14
|
- [Publish](#publish)
|
|
15
15
|
- [Consume](#consume)
|
|
16
16
|
- [Functions](#functions)
|
|
17
|
+
- [setConfig](#setconfig)
|
|
17
18
|
- [useConnection](#useconnection)
|
|
18
19
|
- [publishMessage](#publishmessage)
|
|
19
20
|
- [consumeQueue](#consumequeue)
|
|
@@ -44,11 +45,11 @@ import {
|
|
|
44
45
|
Message,
|
|
45
46
|
useConnection,
|
|
46
47
|
publishMessage,
|
|
47
|
-
|
|
48
|
+
setConfig
|
|
48
49
|
} from "amqp-extension";
|
|
49
50
|
|
|
50
51
|
// This will set the default connection :)
|
|
51
|
-
|
|
52
|
+
setConfig({
|
|
52
53
|
connection: 'amqp://<user>:<password>@<host>',
|
|
53
54
|
exchange: {
|
|
54
55
|
name: '<name>',
|
|
@@ -82,12 +83,12 @@ import {
|
|
|
82
83
|
ConsumeOptions,
|
|
83
84
|
Message,
|
|
84
85
|
MessageContext,
|
|
85
|
-
|
|
86
|
-
|
|
86
|
+
publishMessage,
|
|
87
|
+
setConfig
|
|
87
88
|
} from "amqp-extension";
|
|
88
89
|
|
|
89
90
|
// This will set the default connection :)
|
|
90
|
-
|
|
91
|
+
setConfig({
|
|
91
92
|
connection: 'amqp://<user>:<password>@<host>',
|
|
92
93
|
exchange: {
|
|
93
94
|
name: '<name>',
|
|
@@ -121,13 +122,13 @@ import {
|
|
|
121
122
|
ConsumeOptions,
|
|
122
123
|
Message,
|
|
123
124
|
MessageContext,
|
|
124
|
-
|
|
125
|
-
|
|
125
|
+
publishMessage,
|
|
126
|
+
PublishOptions,
|
|
127
|
+
setConfig
|
|
126
128
|
} from "amqp-extension";
|
|
127
|
-
import {PublishOptions} from "./type";
|
|
128
129
|
|
|
129
130
|
// This will set the default connection :)
|
|
130
|
-
|
|
131
|
+
setConfig({
|
|
131
132
|
connection: 'amqp://<user>:<password>@<host>',
|
|
132
133
|
exchange: {
|
|
133
134
|
name: '<name>',
|
|
@@ -135,7 +136,7 @@ useConnection({
|
|
|
135
136
|
}
|
|
136
137
|
});
|
|
137
138
|
|
|
138
|
-
|
|
139
|
+
setConfig({
|
|
139
140
|
alias: 'foo',
|
|
140
141
|
connection: 'amqp://<user>:<password>@<host>',
|
|
141
142
|
exchange: {
|
|
@@ -162,29 +163,126 @@ const publishOptions: PublishOptions = {
|
|
|
162
163
|
|
|
163
164
|
## Functions
|
|
164
165
|
|
|
166
|
+
### setConfig
|
|
167
|
+
|
|
168
|
+
▸ `function` **setConfig**(`key?: string | Config`, `value?: Config`): `Config`
|
|
169
|
+
|
|
170
|
+
Register a connection as `default` alias or specify an `<alias>` as config property.
|
|
171
|
+
|
|
172
|
+
#### Example
|
|
173
|
+
**`Simple`**
|
|
174
|
+
|
|
175
|
+
Define the default connection config.
|
|
176
|
+
|
|
177
|
+
```typescript
|
|
178
|
+
import {setConfig, useConnection} from "amqp-extension";
|
|
179
|
+
|
|
180
|
+
(async () => {
|
|
181
|
+
setConfig({
|
|
182
|
+
connection: 'amqp://<user>:<password>@<host>',
|
|
183
|
+
exchange: {
|
|
184
|
+
name: '<name>',
|
|
185
|
+
type: 'topic'
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
const connection = await useConnection();
|
|
190
|
+
})();
|
|
191
|
+
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
Define a non default connection.
|
|
195
|
+
|
|
196
|
+
```typescript
|
|
197
|
+
import {setConfig, useConnection} from "amqp-extension";
|
|
198
|
+
|
|
199
|
+
(async () => {
|
|
200
|
+
setConfig({
|
|
201
|
+
alias: '<alias>',
|
|
202
|
+
connection: 'amqp://<user>:<password>@<host>',
|
|
203
|
+
exchange: {
|
|
204
|
+
name: '<name>',
|
|
205
|
+
type: 'topic'
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
setConfig('foo', {
|
|
210
|
+
connection: 'amqp://<user>:<password>@<host>',
|
|
211
|
+
exchange: {
|
|
212
|
+
name: '<name>',
|
|
213
|
+
type: 'topic'
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
const connection = await useConnection('<alias>');
|
|
218
|
+
const fooConnection = await useConnection('foo');
|
|
219
|
+
})();
|
|
220
|
+
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
#### Type parameters
|
|
225
|
+
|
|
226
|
+
| Name | Description |
|
|
227
|
+
| :------ | :------ |
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
#### Parameters
|
|
232
|
+
|
|
233
|
+
| Name | Type | Description |
|
|
234
|
+
| :------ | :------ | :------ |
|
|
235
|
+
| `key` | `string` or `Config` | Config object or alias of config. [more](#config-types) |
|
|
236
|
+
| `value` | `Config` | Config object. [more](#config-types) |
|
|
237
|
+
|
|
238
|
+
#### Returns
|
|
239
|
+
|
|
240
|
+
`Config`
|
|
241
|
+
|
|
242
|
+
The function returns the Config object.
|
|
243
|
+
|
|
165
244
|
### useConnection
|
|
166
245
|
|
|
167
246
|
▸ `function` **useConnection**(`key?: string | Config`): `Promise<Connection>`
|
|
168
247
|
|
|
169
248
|
Either register a connection as `default` alias or specify an `alias` as config property.
|
|
170
249
|
If you have registered a connection you can receive the connection by specifying no arguments or provide an alias name if specified.
|
|
250
|
+
|
|
251
|
+
|
|
171
252
|
#### Example
|
|
172
253
|
**`Simple`**
|
|
173
254
|
|
|
255
|
+
Receive underlying driver connection.
|
|
256
|
+
|
|
174
257
|
```typescript
|
|
175
258
|
import {useConnection} from "amqp-extension";
|
|
176
259
|
|
|
177
260
|
(async () => {
|
|
261
|
+
const connection = await useConnection();
|
|
262
|
+
})();
|
|
263
|
+
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
**`Advanced`**
|
|
267
|
+
|
|
268
|
+
Use a none `default` connection.
|
|
269
|
+
|
|
270
|
+
```typescript
|
|
271
|
+
import {setConfig, useConnection} from "amqp-extension";
|
|
272
|
+
|
|
273
|
+
(async () => {
|
|
274
|
+
setConfig({
|
|
275
|
+
alias: '<alias>',
|
|
276
|
+
connection: 'amqp://<user>:<password>@<host>',
|
|
277
|
+
exchange: {
|
|
278
|
+
name: '<name>',
|
|
279
|
+
type: 'topic'
|
|
280
|
+
}
|
|
281
|
+
});
|
|
178
282
|
|
|
283
|
+
const connection = await useConnection('<alias>');
|
|
179
284
|
})();
|
|
180
|
-
|
|
181
|
-
alias: '<alias>',
|
|
182
|
-
connection: 'amqp://<user>:<password>@<host>',
|
|
183
|
-
exchange: {
|
|
184
|
-
name: '<name>',
|
|
185
|
-
type: 'topic'
|
|
186
|
-
}
|
|
187
|
-
});
|
|
285
|
+
|
|
188
286
|
```
|
|
189
287
|
|
|
190
288
|
#### Type parameters
|
package/dist/config/type.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Options } from
|
|
2
|
-
import { ConsumeOptions } from
|
|
3
|
-
import { PublishOptions } from
|
|
1
|
+
import { Options } from 'amqplib';
|
|
2
|
+
import { ConsumeOptions } from '../consume';
|
|
3
|
+
import { PublishOptions } from '../publish';
|
|
4
4
|
export declare type ExchangeType = 'fanout' | 'direct' | 'topic' | 'match' | string;
|
|
5
5
|
export declare type Config = {
|
|
6
6
|
alias?: string;
|
package/dist/config/utils.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Config } from
|
|
2
|
-
export declare const DEFAULT_KEY
|
|
1
|
+
import { Config } from './type';
|
|
2
|
+
export declare const DEFAULT_KEY = "default";
|
|
3
3
|
export declare function setConfig(key: string | Config, value?: Config): Config;
|
|
4
4
|
export declare function getConfig(key?: string | Config): Config;
|
package/dist/config/utils.js
CHANGED
|
@@ -7,17 +7,15 @@ function setConfig(key, value) {
|
|
|
7
7
|
var _a;
|
|
8
8
|
if (typeof key === 'string') {
|
|
9
9
|
if (typeof value === 'undefined') {
|
|
10
|
-
throw new Error("A config must be defined for the alias: "
|
|
10
|
+
throw new Error("A config must be defined for the alias: ".concat(key));
|
|
11
11
|
}
|
|
12
12
|
value.alias = key;
|
|
13
13
|
configMap.set(key, value);
|
|
14
14
|
return value;
|
|
15
15
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
return key;
|
|
20
|
-
}
|
|
16
|
+
(_a = key.alias) !== null && _a !== void 0 ? _a : (key.alias = exports.DEFAULT_KEY);
|
|
17
|
+
configMap.set(key.alias, key);
|
|
18
|
+
return key;
|
|
21
19
|
}
|
|
22
20
|
exports.setConfig = setConfig;
|
|
23
21
|
function getConfig(key) {
|
|
@@ -26,7 +24,7 @@ function getConfig(key) {
|
|
|
26
24
|
if (typeof key === 'string') {
|
|
27
25
|
var data = configMap.get(key);
|
|
28
26
|
if (typeof data === 'undefined') {
|
|
29
|
-
throw new Error("A config must be defined for the alias: "
|
|
27
|
+
throw new Error("A config must be defined for the alias: ".concat(key));
|
|
30
28
|
}
|
|
31
29
|
return data;
|
|
32
30
|
}
|
package/dist/config/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/config/utils.ts"],"names":[],"mappings":";;;AAEa,QAAA,WAAW,
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/config/utils.ts"],"names":[],"mappings":";;;AAEa,QAAA,WAAW,GAAG,SAAS,CAAC;AAErC,IAAM,SAAS,GAAwB,IAAI,GAAG,EAAkB,CAAC;AAEjE,SAAgB,SAAS,CAAC,GAAoB,EAAE,KAAc;;IAC1D,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE;QACzB,IAAI,OAAO,KAAK,KAAK,WAAW,EAAE;YAC9B,MAAM,IAAI,KAAK,CAAC,kDAA2C,GAAG,CAAE,CAAC,CAAC;SACrE;QAED,KAAK,CAAC,KAAK,GAAG,GAAG,CAAC;QAElB,SAAS,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QAE1B,OAAO,KAAK,CAAC;KAChB;IACD,MAAA,GAAG,CAAC,KAAK,oCAAT,GAAG,CAAC,KAAK,GAAK,mBAAW,EAAC;IAC1B,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAE9B,OAAO,GAAG,CAAC;AACf,CAAC;AAhBD,8BAgBC;AAED,SAAgB,SAAS,CAAC,GAAqB;;IAC3C,GAAG,aAAH,GAAG,cAAH,GAAG,IAAH,GAAG,GAAK,mBAAW,EAAC;IAEpB,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE;QACzB,IAAM,IAAI,GAAwB,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACrD,IAAI,OAAO,IAAI,KAAK,WAAW,EAAE;YAC7B,MAAM,IAAI,KAAK,CAAC,kDAA2C,GAAG,CAAE,CAAC,CAAC;SACrE;QAED,OAAO,IAAI,CAAC;KACf;IAED,IAAM,MAAM,GAAY,GAAG,CAAC;IAC5B,MAAA,MAAM,CAAC,KAAK,oCAAZ,MAAM,CAAC,KAAK,GAAK,mBAAW,EAAC;IAE7B,SAAS,CAAC,MAAM,CAAC,CAAC;IAElB,OAAO,MAAM,CAAC;AAClB,CAAC;AAlBD,8BAkBC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import RabbitMQ, { Connection, Options } from
|
|
2
|
-
import { Config } from
|
|
1
|
+
import RabbitMQ, { Connection, Options } from 'amqplib';
|
|
2
|
+
import { Config } from '../config';
|
|
3
3
|
export declare function clearConnections(): void;
|
|
4
4
|
export declare function getConnections(): Map<string, Connection>;
|
|
5
5
|
export declare function useConnection(key: string | Config): Promise<Connection>;
|
package/dist/connection/utils.js
CHANGED
|
@@ -76,10 +76,7 @@ exports.useConnection = useConnection;
|
|
|
76
76
|
function createConnection(config) {
|
|
77
77
|
return __awaiter(this, void 0, void 0, function () {
|
|
78
78
|
return __generator(this, function (_a) {
|
|
79
|
-
|
|
80
|
-
case 0: return [4 /*yield*/, amqplib_1.default.connect(config)];
|
|
81
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
82
|
-
}
|
|
79
|
+
return [2 /*return*/, amqplib_1.default.connect(config)];
|
|
83
80
|
});
|
|
84
81
|
});
|
|
85
82
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/connection/utils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/connection/utils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oDAAwD;AACxD,oCAA8C;AAE9C,IAAM,aAAa,GAA4B,IAAI,GAAG,EAAsB,CAAC;AAE7E,SAAgB,gBAAgB;IAC5B,aAAa,CAAC,KAAK,EAAE,CAAC;AAC1B,CAAC;AAFD,4CAEC;AAED,SAAgB,cAAc;IAC1B,OAAO,aAAa,CAAC;AACzB,CAAC;AAFD,wCAEC;AAED,0BAA0B;AAC1B,SAAsB,aAAa,CAC/B,GAAoB;;;;;;oBAEd,MAAM,GAAY,IAAA,kBAAS,EAAC,GAAG,CAAC,CAAC;oBAEvC,IAAI,aAAa,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE;wBACjC,sBAAO,aAAa,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,EAAC;qBAC1C;oBAEkB,qBAAM,gBAAgB,CAAC,MAAM,CAAC,UAAU,CAAC,EAAA;;oBAAtD,UAAU,GAAG,SAAyC;oBAE5D,aAAa,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;oBAE5C,sBAAO,UAAU,EAAC;;;;CACrB;AAdD,sCAcC;AAED,0BAA0B;AAC1B,SAAsB,gBAAgB,CAAC,MAAgC;;;YACnE,sBAAO,iBAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,EAAC;;;CACnC;AAFD,4CAEC"}
|
package/dist/consume/index.d.ts
CHANGED
package/dist/consume/index.js
CHANGED
|
@@ -10,6 +10,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
10
10
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
11
|
};
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
__exportStar(require("./static"), exports);
|
|
13
14
|
__exportStar(require("./utils"), exports);
|
|
14
15
|
__exportStar(require("./type"), exports);
|
|
15
16
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/consume/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,0CAAwB;AACxB,yCAAuB"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/consume/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAAyB;AACzB,0CAAwB;AACxB,yCAAuB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const ConsumeHandlerAnyKey = "$any";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"static.js","sourceRoot":"","sources":["../../src/consume/static.ts"],"names":[],"mappings":";;;AAAa,QAAA,oBAAoB,GAAG,MAAM,CAAC"}
|
package/dist/consume/type.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { Options } from
|
|
2
|
-
import { Config } from
|
|
3
|
-
import {
|
|
1
|
+
import { Options } from 'amqplib';
|
|
2
|
+
import { Config } from '../config';
|
|
3
|
+
import { Message, MessageContext } from '../message';
|
|
4
|
+
import { ConsumeHandlerAnyKey } from './static';
|
|
4
5
|
export declare type ConsumeHandler = (message: Message, context: MessageContext) => Promise<void>;
|
|
5
|
-
export declare type
|
|
6
|
+
export declare type ConsumeHandlerAnyKeyType = typeof ConsumeHandlerAnyKey;
|
|
7
|
+
export declare type ConsumeHandlers = Record<ConsumeHandlerAnyKeyType | string, ConsumeHandler>;
|
|
6
8
|
export declare type ConsumeOptions = {
|
|
7
9
|
/**
|
|
8
10
|
* Queue routing key(s).
|
package/dist/consume/utils.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { ConsumeHandlers, ConsumeOptions } from
|
|
1
|
+
import { ConsumeHandlers, ConsumeOptions } from './type';
|
|
2
2
|
export declare function consumeQueue(options: ConsumeOptions, handlers: ConsumeHandlers): Promise<void>;
|
package/dist/consume/utils.js
CHANGED
|
@@ -50,6 +50,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
50
50
|
exports.consumeQueue = void 0;
|
|
51
51
|
var config_1 = require("../config");
|
|
52
52
|
var utils_1 = require("../utils");
|
|
53
|
+
var static_1 = require("./static");
|
|
53
54
|
/* istanbul ignore next */
|
|
54
55
|
function consumeQueue(options, handlers) {
|
|
55
56
|
var _a, _b, _c, _d;
|
|
@@ -66,15 +67,14 @@ function consumeQueue(options, handlers) {
|
|
|
66
67
|
queueName = (_a = options.name) !== null && _a !== void 0 ? _a : '';
|
|
67
68
|
return [4 /*yield*/, channel.assertQueue(queueName, {
|
|
68
69
|
durable: false,
|
|
69
|
-
autoDelete: true
|
|
70
|
+
autoDelete: true,
|
|
70
71
|
})];
|
|
71
72
|
case 2:
|
|
72
73
|
assertionQueue = _f.sent();
|
|
73
74
|
if (!(typeof options.routingKey !== 'undefined')) return [3 /*break*/, 4];
|
|
74
75
|
routingKeys = Array.isArray(options.routingKey) ? options.routingKey : [options.routingKey];
|
|
75
|
-
promises = routingKeys
|
|
76
|
-
return channel.bindQueue(assertionQueue.queue, config.exchange.name, routKey);
|
|
77
|
-
});
|
|
76
|
+
promises = routingKeys
|
|
77
|
+
.map(function (routKey) { return channel.bindQueue(assertionQueue.queue, config.exchange.name, routKey); });
|
|
78
78
|
return [4 /*yield*/, Promise.all(promises)];
|
|
79
79
|
case 3:
|
|
80
80
|
_f.sent();
|
|
@@ -82,7 +82,7 @@ function consumeQueue(options, handlers) {
|
|
|
82
82
|
case 4:
|
|
83
83
|
consumeOptions = __assign(__assign({}, ((_c = (_b = config.consume) === null || _b === void 0 ? void 0 : _b.options) !== null && _c !== void 0 ? _c : {})), ((_d = options.options) !== null && _d !== void 0 ? _d : {}));
|
|
84
84
|
return [4 /*yield*/, channel.consume(assertionQueue.queue, ((function (message) { return __awaiter(_this, void 0, void 0, function () {
|
|
85
|
-
var content, handler, context,
|
|
85
|
+
var content, handler, context, requeueOnFailure, e_1;
|
|
86
86
|
var _a, _b, _c;
|
|
87
87
|
return __generator(this, function (_d) {
|
|
88
88
|
switch (_d.label) {
|
|
@@ -91,34 +91,31 @@ function consumeQueue(options, handlers) {
|
|
|
91
91
|
return [2 /*return*/];
|
|
92
92
|
}
|
|
93
93
|
content = JSON.parse(message.content.toString('utf-8'));
|
|
94
|
-
handler = (_a = handlers[content.type]) !== null && _a !== void 0 ? _a : handlers
|
|
94
|
+
handler = (_a = handlers[content.type]) !== null && _a !== void 0 ? _a : handlers[static_1.ConsumeHandlerAnyKey];
|
|
95
95
|
context = {
|
|
96
96
|
channel: channel,
|
|
97
97
|
connection: connection,
|
|
98
98
|
messageFields: message.fields,
|
|
99
|
-
messageProperties: message.properties
|
|
99
|
+
messageProperties: message.properties,
|
|
100
100
|
};
|
|
101
|
+
requeueOnFailure = (_c = (_b = config.consume) === null || _b === void 0 ? void 0 : _b.requeueOnFailure) !== null && _c !== void 0 ? _c : false;
|
|
101
102
|
if (typeof handler === 'undefined') {
|
|
102
|
-
channel.
|
|
103
|
+
channel.reject(message, requeueOnFailure);
|
|
104
|
+
return [2 /*return*/];
|
|
103
105
|
}
|
|
104
106
|
_d.label = 1;
|
|
105
107
|
case 1:
|
|
106
|
-
_d.trys.push([1,
|
|
108
|
+
_d.trys.push([1, 3, , 4]);
|
|
107
109
|
return [4 /*yield*/, handler(content, context)];
|
|
108
110
|
case 2:
|
|
109
111
|
_d.sent();
|
|
110
|
-
|
|
112
|
+
channel.ack(message);
|
|
113
|
+
return [3 /*break*/, 4];
|
|
111
114
|
case 3:
|
|
112
|
-
_d.sent();
|
|
113
|
-
return [3 /*break*/, 6];
|
|
114
|
-
case 4:
|
|
115
115
|
e_1 = _d.sent();
|
|
116
|
-
|
|
117
|
-
return [
|
|
118
|
-
case
|
|
119
|
-
_d.sent();
|
|
120
|
-
return [3 /*break*/, 6];
|
|
121
|
-
case 6: return [2 /*return*/];
|
|
116
|
+
channel.reject(message, requeueOnFailure);
|
|
117
|
+
return [3 /*break*/, 4];
|
|
118
|
+
case 4: return [2 /*return*/];
|
|
122
119
|
}
|
|
123
120
|
});
|
|
124
121
|
}); })), consumeOptions)];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/consume/utils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/consume/utils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,oCAA8C;AAE9C,kCAAyC;AAEzC,mCAAgD;AAEhD,0BAA0B;AAC1B,SAAsB,YAAY,CAC9B,OAAuB,EACvB,QAAyB;;;;;;;;oBAEnB,MAAM,GAAY,IAAA,kBAAS,EAAC,OAAO,CAAC,KAAK,CAAC,CAAC;oBACjB,qBAAM,IAAA,qBAAa,EAAC,MAAM,CAAC,EAAA;;oBAArD,KAA0B,SAA2B,EAAnD,OAAO,aAAA,EAAE,UAAU,gBAAA;oBAErB,SAAS,GAAY,MAAA,OAAO,CAAC,IAAI,mCAAI,EAAE,CAAC;oBAEvB,qBAAM,OAAO,CAAC,WAAW,CAAC,SAAS,EAAE;4BACxD,OAAO,EAAE,KAAK;4BACd,UAAU,EAAE,IAAI;yBACnB,CAAC,EAAA;;oBAHI,cAAc,GAAG,SAGrB;yBAEE,CAAA,OAAO,OAAO,CAAC,UAAU,KAAK,WAAW,CAAA,EAAzC,wBAAyC;oBACnC,WAAW,GAAa,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;oBAEtG,QAAQ,GAA6B,WAAW;yBACjD,GAAG,CAAC,UAAC,OAAO,IAAK,OAAA,OAAO,CAAC,SAAS,CAAC,cAAc,CAAC,KAAK,EAAE,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAsC,EAA3G,CAA2G,CAAC,CAAC;oBAEnI,qBAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAA;;oBAA3B,SAA2B,CAAC;;;oBAG1B,cAAc,yBACb,CAAC,MAAA,MAAA,MAAM,CAAC,OAAO,0CAAE,OAAO,mCAAI,EAAE,CAAC,GAC/B,CAAC,MAAA,OAAO,CAAC,OAAO,mCAAI,EAAE,CAAC,CAC7B,CAAC;oBAEF,qBAAM,OAAO,CAAC,OAAO,CAAC,cAAc,CAAC,KAAK,EAAE,CAAC,CAAC,UAAO,OAAO;;;;;;wCACxD,IAAI,CAAC,OAAO,EAAE;4CACV,sBAAO;yCACV;wCAEK,OAAO,GAAa,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC;wCAClE,OAAO,GAAG,MAAA,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,mCAAI,QAAQ,CAAC,6BAAoB,CAAC,CAAC;wCAEnE,OAAO,GAAoB;4CAC7B,OAAO,SAAA;4CACP,UAAU,YAAA;4CACV,aAAa,EAAE,OAAO,CAAC,MAAM;4CAC7B,iBAAiB,EAAE,OAAO,CAAC,UAAU;yCACxC,CAAC;wCAEI,gBAAgB,GAAa,MAAA,MAAA,MAAM,CAAC,OAAO,0CAAE,gBAAgB,mCAAI,KAAK,CAAC;wCAE7E,IAAI,OAAO,OAAO,KAAK,WAAW,EAAE;4CAChC,OAAO,CAAC,MAAM,CAAC,OAAO,EAAE,gBAAgB,CAAC,CAAC;4CAC1C,sBAAO;yCACV;;;;wCAGG,qBAAM,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,EAAA;;wCAA/B,SAA+B,CAAC;wCAChC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;;;;wCAErB,OAAO,CAAC,MAAM,CAAC,OAAO,EAAE,gBAAgB,CAAC,CAAC;;;;;6BAEjD,CAAC,CAAC,EAAE,cAAc,CAAC,EAAA;;oBA5BpB,SA4BoB,CAAC;;;;;CACxB;AAzDD,oCAyDC"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -10,12 +10,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
10
10
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
11
|
};
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.publishMessage = void 0;
|
|
14
13
|
__exportStar(require("./config"), exports);
|
|
15
14
|
__exportStar(require("./consume"), exports);
|
|
16
15
|
__exportStar(require("./connection"), exports);
|
|
17
16
|
__exportStar(require("./message"), exports);
|
|
18
17
|
__exportStar(require("./publish"), exports);
|
|
19
|
-
var publish_1 = require("./publish");
|
|
20
|
-
Object.defineProperty(exports, "publishMessage", { enumerable: true, get: function () { return publish_1.publishMessage; } });
|
|
21
18
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAAyB;AACzB,4CAA0B;AAC1B,+CAA6B;AAC7B,4CAA0B;AAC1B,4CAA0B"}
|
package/dist/message/build.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { BuildMessageContext, Message } from
|
|
1
|
+
import { BuildMessageContext, Message } from './type';
|
|
2
2
|
export declare function buildMessage(context: BuildMessageContext): Message;
|
package/dist/message/build.js
CHANGED
|
@@ -9,7 +9,7 @@ function buildMessage(context) {
|
|
|
9
9
|
type: context.type,
|
|
10
10
|
options: (_b = context.options) !== null && _b !== void 0 ? _b : {},
|
|
11
11
|
data: (_c = context.data) !== null && _c !== void 0 ? _c : {},
|
|
12
|
-
metadata: (_d = context.metadata) !== null && _d !== void 0 ? _d : {}
|
|
12
|
+
metadata: (_d = context.metadata) !== null && _d !== void 0 ? _d : {},
|
|
13
13
|
};
|
|
14
14
|
}
|
|
15
15
|
exports.buildMessage = buildMessage;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.js","sourceRoot":"","sources":["../../src/message/build.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"build.js","sourceRoot":"","sources":["../../src/message/build.ts"],"names":[],"mappings":";;;AAAA,6BAA0B;AAG1B,SAAgB,YAAY,CACxB,OAA4B;;IAE5B,OAAO;QACH,EAAE,EAAE,MAAA,OAAO,CAAC,EAAE,mCAAI,IAAA,SAAE,GAAE;QACtB,IAAI,EAAE,OAAO,CAAC,IAAI;QAClB,OAAO,EAAE,MAAA,OAAO,CAAC,OAAO,mCAAI,EAAE;QAC9B,IAAI,EAAE,MAAA,OAAO,CAAC,IAAI,mCAAI,EAAE;QACxB,QAAQ,EAAE,MAAA,OAAO,CAAC,QAAQ,mCAAI,EAAE;KACnC,CAAC;AACN,CAAC;AAVD,oCAUC"}
|
package/dist/message/type.d.ts
CHANGED
package/dist/publish/type.d.ts
CHANGED
package/dist/publish/utils.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { Message } from
|
|
2
|
-
import { PublishOptions } from
|
|
1
|
+
import { Message } from '../message';
|
|
2
|
+
import { PublishOptions } from './type';
|
|
3
3
|
export declare function publishMessage(message: Message, options?: PublishOptions): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/publish/utils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/publish/utils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,oCAA8C;AAE9C,kCAAyC;AAGzC,0BAA0B;AAC1B,SAAsB,cAAc,CAChC,OAAgB,EAChB,OAAwB;;;;;;;oBAEP,cAAc,GAAwB,OAAO,QAA/B,EAAK,cAAc,UAAK,OAAO,EAAxD,WAA8C,CAAF,CAAa;oBAEzD,MAAM,GAAW,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC,CAAC;oBAEnE,OAAO,aAAP,OAAO,cAAP,OAAO,IAAP,OAAO,GAAK,EAAE,EAAC;oBACT,MAAM,GAAW,IAAA,kBAAS,EAAC,OAAO,CAAC,KAAK,CAAC,CAAC;oBAC5B,qBAAM,IAAA,qBAAa,EAAC,MAAM,CAAC,EAAA;;oBAAvC,OAAO,GAAK,CAAA,SAA2B,CAAA,QAAhC;oBAET,cAAc,kCACb,CAAC,MAAA,MAAA,MAAM,CAAC,OAAO,0CAAE,OAAO,mCAAI,EAAE,CAAC,GAC/B,CAAC,MAAA,cAAc,CAAC,OAAO,mCAAI,EAAE,CAAC,GAC9B,CAAC,MAAA,OAAO,CAAC,OAAO,mCAAI,EAAE,CAAC,CAC7B,CAAC;oBAEF,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAC,UAAU,EAAE,MAAM,EAAE,cAAc,CAAC,CAAC;;;;;CAC5F;AAnBD,wCAmBC"}
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Channel, Connection } from
|
|
2
|
-
import { Config } from
|
|
1
|
+
import { Channel, Connection } from 'amqplib';
|
|
2
|
+
import { Config } from './config';
|
|
3
3
|
export declare function createChannel(key: string | Config): Promise<{
|
|
4
4
|
channel: Channel;
|
|
5
5
|
connection: Connection;
|
package/dist/utils.js
CHANGED
package/dist/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,mCAA6C;AAC7C,2CAA6C;AAE7C,0BAA0B;AAC1B,SAAsB,aAAa,CAAC,GAAoB;;;;;;;oBAI9C,MAAM,GAAY,IAAA,kBAAS,EAAC,GAAG,CAAC,CAAC;oBAEP,qBAAM,IAAA,0BAAa,EAAC,MAAM,CAAC,KAAK,CAAC,EAAA;;oBAA3D,UAAU,GAAgB,SAAiC;oBACvC,qBAAM,UAAU,CAAC,aAAa,EAAE,EAAA;;oBAApD,OAAO,GAAa,SAAgC;oBAEpD,eAAe,cACjB,OAAO,EAAE,IAAI,IACV,CAAC,MAAA,MAAA,MAAM,CAAC,QAAQ,0CAAE,OAAO,mCAAI,EAAE,CAAC,CACtC,CAAC;oBAEF,qBAAM,OAAO,CAAC,cAAc,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,eAAe,CAAC,EAAA;;oBAAzF,SAAyF,CAAC;oBAE1F,sBAAO;4BACH,OAAO,SAAA;4BACP,UAAU,YAAA;yBACb,EAAC;;;;CACL;AApBD,sCAoBC"}
|
package/package.json
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "amqp-extension",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "An amqp extension with functions and utility functions to consume and publish queue messages.",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
|
+
"typings": "dist/index.d.ts",
|
|
6
7
|
"scripts": {
|
|
7
8
|
"build": "rm -rf ./dist && tsc",
|
|
8
9
|
"test": "cross-env NODE_ENV=test jest --config ./test/jest.config.js",
|
|
9
|
-
"test:coverage": "cross-env NODE_ENV=test jest --config ./test/jest.config.js --coverage"
|
|
10
|
+
"test:coverage": "cross-env NODE_ENV=test jest --config ./test/jest.config.js --coverage",
|
|
11
|
+
"lint": "eslint --ext .js,.vue,.ts ./src",
|
|
12
|
+
"lint:fix": "npm run lint -- --fix"
|
|
10
13
|
},
|
|
11
14
|
"author": {
|
|
12
15
|
"name": "Peter Placzek",
|
|
13
|
-
"email": "
|
|
14
|
-
"url": "https
|
|
16
|
+
"email": "contact@tada5hi.net",
|
|
17
|
+
"url": "https://github.com/tada5hi"
|
|
15
18
|
},
|
|
16
19
|
"license": "MIT",
|
|
17
20
|
"keywords": [
|
|
@@ -26,23 +29,27 @@
|
|
|
26
29
|
"type": "git",
|
|
27
30
|
"url": "git+https://github.com/Tada5hi/amqp-extension.git"
|
|
28
31
|
},
|
|
32
|
+
"bugs": {
|
|
33
|
+
"url": "https://github.com/Tada5hi/amqp-extension/issues"
|
|
34
|
+
},
|
|
35
|
+
"homepage": "https://github.com/Tada5hi/amqp-extension#readme",
|
|
29
36
|
"dependencies": {
|
|
30
37
|
"amqplib": "^0.8.0",
|
|
31
38
|
"uuid": "^8.3.2"
|
|
32
39
|
},
|
|
33
40
|
"devDependencies": {
|
|
41
|
+
"@tada5hi/eslint-config-typescript": "^0.0.24",
|
|
34
42
|
"@types/amqplib": "^0.8.2",
|
|
35
|
-
"@types/jest": "^27.0.
|
|
36
|
-
"@types/node": "^
|
|
37
|
-
"@types/uuid": "^8.3.
|
|
43
|
+
"@types/jest": "^27.0.3",
|
|
44
|
+
"@types/node": "^17.0.2",
|
|
45
|
+
"@types/uuid": "^8.3.3",
|
|
38
46
|
"codecov": "^3.8.3",
|
|
39
47
|
"coveralls": "^3.1.0",
|
|
40
48
|
"cross-env": "^7.0.3",
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"typescript": "^4.4.3"
|
|
49
|
+
"eslint": "^8.5.0",
|
|
50
|
+
"jest": "^27.4.5",
|
|
51
|
+
"np": "^7.6.0",
|
|
52
|
+
"ts-jest": "^27.1.2",
|
|
53
|
+
"typescript": "^4.5.4"
|
|
47
54
|
}
|
|
48
55
|
}
|