amqp-extension 0.0.4 → 0.0.5
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/README.MD +1 -1
- package/dist/config/index.d.ts +2 -0
- package/dist/config/index.js +15 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/type.d.ts +15 -0
- package/dist/{connection → config}/type.js +0 -0
- package/dist/{connection → config}/type.js.map +1 -1
- package/dist/config/utils.d.ts +4 -0
- package/dist/config/utils.js +39 -0
- package/dist/config/utils.js.map +1 -0
- package/dist/connection/index.d.ts +0 -1
- package/dist/connection/index.js +0 -1
- package/dist/connection/index.js.map +1 -1
- package/dist/connection/utils.d.ts +5 -5
- package/dist/connection/utils.js +11 -9
- package/dist/connection/utils.js.map +1 -1
- package/dist/consume/index.d.ts +2 -0
- package/dist/consume/index.js +15 -0
- package/dist/consume/index.js.map +1 -0
- package/dist/consume/type.d.ts +31 -0
- package/dist/consume/type.js +3 -0
- package/dist/consume/type.js.map +1 -0
- package/dist/consume/utils.d.ts +2 -0
- package/dist/consume/utils.js +133 -0
- package/dist/consume/utils.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -1
- package/dist/message/build.d.ts +2 -0
- package/dist/message/build.js +16 -0
- package/dist/message/build.js.map +1 -0
- package/dist/message/index.d.ts +2 -0
- package/dist/message/index.js +15 -0
- package/dist/message/index.js.map +1 -0
- package/dist/message/type.d.ts +46 -0
- package/dist/message/type.js +3 -0
- package/dist/message/type.js.map +1 -0
- package/dist/publish/index.d.ts +2 -0
- package/dist/publish/index.js +15 -0
- package/dist/publish/index.js.map +1 -0
- package/dist/publish/type.d.ts +12 -0
- package/dist/publish/type.js +3 -0
- package/dist/publish/type.js.map +1 -0
- package/dist/publish/utils.d.ts +3 -0
- package/dist/publish/utils.js +87 -0
- package/dist/publish/utils.js.map +1 -0
- package/dist/utils.d.ts +6 -0
- package/dist/utils.js +81 -0
- package/dist/utils.js.map +1 -0
- package/package.json +1 -1
- package/dist/connection/type.d.ts +0 -1
package/README.MD
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
# AMQP Extension 🏰
|
|
6
6
|
|
|
7
|
-
This is a library on top of the famous [amqplib](https://www.npmjs.com/package/amqplib) library and defines a [message format](#message-types) for queue
|
|
7
|
+
This is a library on top of the famous [amqplib](https://www.npmjs.com/package/amqplib) library and defines a [message format](#message-types) for queue messages through a message broker across multiple standalone services.
|
|
8
8
|
All utility functions support the usage of multiple registered connections.
|
|
9
9
|
|
|
10
10
|
**Table of Contents**
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
__exportStar(require("./type"), exports);
|
|
14
|
+
__exportStar(require("./utils"), exports);
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,yCAAuB;AACvB,0CAAwB"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Options } from "amqplib";
|
|
2
|
+
import { ConsumeOptions } from "../consume";
|
|
3
|
+
import { PublishOptions } from "../publish";
|
|
4
|
+
export declare type ExchangeType = 'fanout' | 'direct' | 'topic' | 'match' | string;
|
|
5
|
+
export declare type Config = {
|
|
6
|
+
alias?: string;
|
|
7
|
+
connection: Options.Connect | string;
|
|
8
|
+
exchange: {
|
|
9
|
+
name: string;
|
|
10
|
+
type: ExchangeType;
|
|
11
|
+
options?: Options.AssertExchange;
|
|
12
|
+
};
|
|
13
|
+
publish?: PublishOptions;
|
|
14
|
+
consume?: ConsumeOptions;
|
|
15
|
+
};
|
|
File without changes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type.js","sourceRoot":"","sources":["../../src/
|
|
1
|
+
{"version":3,"file":"type.js","sourceRoot":"","sources":["../../src/config/type.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getConfig = exports.setConfig = exports.DEFAULT_KEY = void 0;
|
|
4
|
+
exports.DEFAULT_KEY = 'default';
|
|
5
|
+
var configMap = new Map();
|
|
6
|
+
function setConfig(key, value) {
|
|
7
|
+
var _a;
|
|
8
|
+
if (typeof key === 'string') {
|
|
9
|
+
if (typeof value === 'undefined') {
|
|
10
|
+
throw new Error("A config must be defined for the alias: " + key);
|
|
11
|
+
}
|
|
12
|
+
value.alias = key;
|
|
13
|
+
configMap.set(key, value);
|
|
14
|
+
return value;
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
(_a = key.alias) !== null && _a !== void 0 ? _a : (key.alias = exports.DEFAULT_KEY);
|
|
18
|
+
configMap.set(key.alias, key);
|
|
19
|
+
return key;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.setConfig = setConfig;
|
|
23
|
+
function getConfig(key) {
|
|
24
|
+
var _a;
|
|
25
|
+
key !== null && key !== void 0 ? key : (key = exports.DEFAULT_KEY);
|
|
26
|
+
if (typeof key === 'string') {
|
|
27
|
+
var data = configMap.get(key);
|
|
28
|
+
if (typeof data === 'undefined') {
|
|
29
|
+
throw new Error("A config must be defined for the alias: " + key);
|
|
30
|
+
}
|
|
31
|
+
return data;
|
|
32
|
+
}
|
|
33
|
+
var config = key;
|
|
34
|
+
(_a = config.alias) !== null && _a !== void 0 ? _a : (config.alias = exports.DEFAULT_KEY);
|
|
35
|
+
setConfig(config);
|
|
36
|
+
return config;
|
|
37
|
+
}
|
|
38
|
+
exports.getConfig = getConfig;
|
|
39
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/config/utils.ts"],"names":[],"mappings":";;;AAEa,QAAA,WAAW,GAAY,SAAS,CAAC;AAE9C,IAAM,SAAS,GAAwB,IAAI,GAAG,EAAkB,CAAC;AAEjE,SAAgB,SAAS,CAAC,GAAoB,EAAE,KAAc;;IAC1D,IAAG,OAAO,GAAG,KAAK,QAAQ,EAAE;QACxB,IAAG,OAAO,KAAK,KAAK,WAAW,EAAE;YAC7B,MAAM,IAAI,KAAK,CAAC,6CAA2C,GAAK,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;SAAM;QACH,MAAA,GAAG,CAAC,KAAK,oCAAT,GAAG,CAAC,KAAK,GAAK,mBAAW,EAAC;QAC1B,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;QAE9B,OAAO,GAAG,CAAC;KACd;AACL,CAAC;AAjBD,8BAiBC;AAED,SAAgB,SAAS,CAAC,GAAqB;;IAC3C,GAAG,aAAH,GAAG,cAAH,GAAG,IAAH,GAAG,GAAK,mBAAW,EAAC;IAEpB,IAAG,OAAO,GAAG,KAAK,QAAQ,EAAE;QACxB,IAAM,IAAI,GAAwB,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACrD,IAAG,OAAO,IAAI,KAAK,WAAW,EAAE;YAC5B,MAAM,IAAI,KAAK,CAAC,6CAA2C,GAAK,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"}
|
package/dist/connection/index.js
CHANGED
|
@@ -10,6 +10,5 @@ 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("./type"), exports);
|
|
14
13
|
__exportStar(require("./utils"), exports);
|
|
15
14
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/connection/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/connection/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,0CAAwB"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import RabbitMQ, { Connection } from "amqplib";
|
|
2
|
-
import {
|
|
1
|
+
import RabbitMQ, { Connection, Options } from "amqplib";
|
|
2
|
+
import { Config } from "../config";
|
|
3
3
|
export declare function clearConnections(): void;
|
|
4
|
-
export declare function getConnections(): Map<
|
|
5
|
-
export declare function useConnection(
|
|
6
|
-
export declare function createConnection(config: string): Promise<RabbitMQ.Connection>;
|
|
4
|
+
export declare function getConnections(): Map<string, Connection>;
|
|
5
|
+
export declare function useConnection(key: string | Config): Promise<Connection>;
|
|
6
|
+
export declare function createConnection(config: Options.Connect | string): Promise<RabbitMQ.Connection>;
|
package/dist/connection/utils.js
CHANGED
|
@@ -41,29 +41,31 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
41
41
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
42
|
exports.createConnection = exports.useConnection = exports.getConnections = exports.clearConnections = void 0;
|
|
43
43
|
var amqplib_1 = __importDefault(require("amqplib"));
|
|
44
|
-
var
|
|
44
|
+
var config_1 = require("../config");
|
|
45
|
+
var connectionMap = new Map();
|
|
45
46
|
function clearConnections() {
|
|
46
|
-
|
|
47
|
+
connectionMap.clear();
|
|
47
48
|
}
|
|
48
49
|
exports.clearConnections = clearConnections;
|
|
49
50
|
function getConnections() {
|
|
50
|
-
return
|
|
51
|
+
return connectionMap;
|
|
51
52
|
}
|
|
52
53
|
exports.getConnections = getConnections;
|
|
53
54
|
/* istanbul ignore next */
|
|
54
|
-
function useConnection(
|
|
55
|
+
function useConnection(key) {
|
|
55
56
|
return __awaiter(this, void 0, void 0, function () {
|
|
56
|
-
var connection;
|
|
57
|
+
var config, connection;
|
|
57
58
|
return __generator(this, function (_a) {
|
|
58
59
|
switch (_a.label) {
|
|
59
60
|
case 0:
|
|
60
|
-
|
|
61
|
-
|
|
61
|
+
config = (0, config_1.getConfig)(key);
|
|
62
|
+
if (connectionMap.has(config.alias)) {
|
|
63
|
+
return [2 /*return*/, connectionMap.get(config.alias)];
|
|
62
64
|
}
|
|
63
|
-
return [4 /*yield*/, createConnection(config)];
|
|
65
|
+
return [4 /*yield*/, createConnection(config.connection)];
|
|
64
66
|
case 1:
|
|
65
67
|
connection = _a.sent();
|
|
66
|
-
|
|
68
|
+
connectionMap.set(config.alias, connection);
|
|
67
69
|
return [2 /*return*/, connection];
|
|
68
70
|
}
|
|
69
71
|
});
|
|
@@ -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,oDAAsD;AACtD,oCAA4C;AAE5C,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,IAAG,aAAa,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE;wBAChC,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;;;;wBAC5D,qBAAM,iBAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,EAAA;wBAArC,sBAAO,SAA8B,EAAC;;;;CACzC;AAFD,4CAEC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
__exportStar(require("./utils"), exports);
|
|
14
|
+
__exportStar(require("./type"), exports);
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/consume/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,0CAAwB;AACxB,yCAAuB"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Options } from "amqplib";
|
|
2
|
+
import { Config } from "../config";
|
|
3
|
+
import { MessageContext, Message } from "../message";
|
|
4
|
+
export declare type ConsumeHandler = (message: Message, context: MessageContext) => Promise<void>;
|
|
5
|
+
export declare type ConsumeHandlers = Record<'$any' | string, ConsumeHandler>;
|
|
6
|
+
export declare type ConsumeOptions = {
|
|
7
|
+
/**
|
|
8
|
+
* Queue routing key(s).
|
|
9
|
+
*/
|
|
10
|
+
routingKey?: string | string[];
|
|
11
|
+
/**
|
|
12
|
+
* Config key or object.
|
|
13
|
+
*/
|
|
14
|
+
alias?: string | Config;
|
|
15
|
+
/**
|
|
16
|
+
* Queue name.
|
|
17
|
+
*
|
|
18
|
+
* Default: ''
|
|
19
|
+
*/
|
|
20
|
+
name?: string;
|
|
21
|
+
/**
|
|
22
|
+
* Amqplib consume options.
|
|
23
|
+
*
|
|
24
|
+
* Default: { }
|
|
25
|
+
*/
|
|
26
|
+
options?: Options.Consume;
|
|
27
|
+
/**
|
|
28
|
+
* Default: false
|
|
29
|
+
*/
|
|
30
|
+
requeueOnFailure?: boolean;
|
|
31
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.js","sourceRoot":"","sources":["../../src/consume/type.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
+
function step(op) {
|
|
27
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
+
while (_) try {
|
|
29
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
+
switch (op[0]) {
|
|
32
|
+
case 0: case 1: t = op; break;
|
|
33
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
+
default:
|
|
37
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
+
if (t[2]) _.ops.pop();
|
|
42
|
+
_.trys.pop(); continue;
|
|
43
|
+
}
|
|
44
|
+
op = body.call(thisArg, _);
|
|
45
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
|
+
exports.consumeQueue = void 0;
|
|
51
|
+
var config_1 = require("../config");
|
|
52
|
+
var utils_1 = require("../utils");
|
|
53
|
+
/* istanbul ignore next */
|
|
54
|
+
function consumeQueue(options, handlers) {
|
|
55
|
+
var _a, _b, _c, _d;
|
|
56
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
57
|
+
var config, _e, channel, connection, queueName, assertionQueue, routingKeys, promises, consumeOptions;
|
|
58
|
+
var _this = this;
|
|
59
|
+
return __generator(this, function (_f) {
|
|
60
|
+
switch (_f.label) {
|
|
61
|
+
case 0:
|
|
62
|
+
config = (0, config_1.getConfig)(options.alias);
|
|
63
|
+
return [4 /*yield*/, (0, utils_1.createChannel)(config)];
|
|
64
|
+
case 1:
|
|
65
|
+
_e = _f.sent(), channel = _e.channel, connection = _e.connection;
|
|
66
|
+
queueName = (_a = options.name) !== null && _a !== void 0 ? _a : '';
|
|
67
|
+
return [4 /*yield*/, channel.assertQueue(queueName, {
|
|
68
|
+
durable: false,
|
|
69
|
+
autoDelete: true
|
|
70
|
+
})];
|
|
71
|
+
case 2:
|
|
72
|
+
assertionQueue = _f.sent();
|
|
73
|
+
if (!(typeof options.routingKey !== 'undefined')) return [3 /*break*/, 4];
|
|
74
|
+
routingKeys = Array.isArray(options.routingKey) ? options.routingKey : [options.routingKey];
|
|
75
|
+
promises = routingKeys.map(function (routKey) {
|
|
76
|
+
return channel.bindQueue(assertionQueue.queue, config.exchange.name, routKey);
|
|
77
|
+
});
|
|
78
|
+
return [4 /*yield*/, Promise.all(promises)];
|
|
79
|
+
case 3:
|
|
80
|
+
_f.sent();
|
|
81
|
+
_f.label = 4;
|
|
82
|
+
case 4:
|
|
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
|
+
return [4 /*yield*/, channel.consume(assertionQueue.queue, ((function (message) { return __awaiter(_this, void 0, void 0, function () {
|
|
85
|
+
var content, handler, context, e_1, requeueOnFailure;
|
|
86
|
+
var _a, _b, _c;
|
|
87
|
+
return __generator(this, function (_d) {
|
|
88
|
+
switch (_d.label) {
|
|
89
|
+
case 0:
|
|
90
|
+
if (!message) {
|
|
91
|
+
return [2 /*return*/];
|
|
92
|
+
}
|
|
93
|
+
content = JSON.parse(message.content.toString('utf-8'));
|
|
94
|
+
handler = (_a = handlers[content.type]) !== null && _a !== void 0 ? _a : handlers.$any;
|
|
95
|
+
context = {
|
|
96
|
+
channel: channel,
|
|
97
|
+
connection: connection,
|
|
98
|
+
messageFields: message.fields,
|
|
99
|
+
messageProperties: message.properties
|
|
100
|
+
};
|
|
101
|
+
if (typeof handler === 'undefined') {
|
|
102
|
+
channel.ack(message);
|
|
103
|
+
}
|
|
104
|
+
_d.label = 1;
|
|
105
|
+
case 1:
|
|
106
|
+
_d.trys.push([1, 4, , 6]);
|
|
107
|
+
return [4 /*yield*/, handler(content, context)];
|
|
108
|
+
case 2:
|
|
109
|
+
_d.sent();
|
|
110
|
+
return [4 /*yield*/, channel.ack(message)];
|
|
111
|
+
case 3:
|
|
112
|
+
_d.sent();
|
|
113
|
+
return [3 /*break*/, 6];
|
|
114
|
+
case 4:
|
|
115
|
+
e_1 = _d.sent();
|
|
116
|
+
requeueOnFailure = (_c = (_b = config.consume) === null || _b === void 0 ? void 0 : _b.requeueOnFailure) !== null && _c !== void 0 ? _c : false;
|
|
117
|
+
return [4 /*yield*/, channel.reject(message, requeueOnFailure)];
|
|
118
|
+
case 5:
|
|
119
|
+
_d.sent();
|
|
120
|
+
return [3 /*break*/, 6];
|
|
121
|
+
case 6: return [2 /*return*/];
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
}); })), consumeOptions)];
|
|
125
|
+
case 5:
|
|
126
|
+
_f.sent();
|
|
127
|
+
return [2 /*return*/];
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
exports.consumeQueue = consumeQueue;
|
|
133
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/consume/utils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,oCAA4C;AAE5C,kCAAuC;AAIvC,0BAA0B;AAC1B,SAAsB,YAAY,CAC9B,OAAuB,EACvB,QAAyB;;;;;;;;oBAEnB,MAAM,GAAY,IAAA,kBAAS,EAAC,OAAO,CAAC,KAAK,CAAC,CAAC;oBACnB,qBAAM,IAAA,qBAAa,EAAC,MAAM,CAAC,EAAA;;oBAAnD,KAAwB,SAA2B,EAAlD,OAAO,aAAA,EAAE,UAAU,gBAAA;oBAEpB,SAAS,GAAY,MAAA,OAAO,CAAC,IAAI,mCAAI,EAAE,CAAC;oBACvB,qBAAM,OAAO,CAAC,WAAW,CAAC,SAAS,EAAE;4BACxD,OAAO,EAAE,KAAK;4BACd,UAAU,EAAE,IAAI;yBACnB,CAAC,EAAA;;oBAHI,cAAc,GAAG,SAGrB;yBAEC,CAAA,OAAO,OAAO,CAAC,UAAU,KAAK,WAAW,CAAA,EAAzC,wBAAyC;oBAClC,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,CAAC,GAAG,CAAC,UAAA,OAAO;wBAC9D,OAAO,OAAO,CAAC,SAAS,CAAC,cAAc,CAAC,KAAK,EAAE,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAA8B,CAAC;oBAC/G,CAAC,CAAC,CAAC;oBAEH,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,IAAG,CAAC,OAAO,EAAE;4CACT,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,IAAI,CAAC;wCAElD,OAAO,GAAoB;4CAC7B,OAAO,EAAE,OAAO;4CAChB,UAAU,EAAE,UAAU;4CACtB,aAAa,EAAE,OAAO,CAAC,MAAM;4CAC7B,iBAAiB,EAAE,OAAO,CAAC,UAAU;yCACxC,CAAA;wCAED,IAAG,OAAO,OAAO,KAAK,WAAW,EAAE;4CAC/B,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;yCACxB;;;;wCAGG,qBAAM,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,EAAA;;wCAA/B,SAA+B,CAAC;wCAChC,qBAAM,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,EAAA;;wCAA1B,SAA0B,CAAC;;;;wCAErB,gBAAgB,GAAa,MAAA,MAAA,MAAM,CAAC,OAAO,0CAAE,gBAAgB,mCAAI,KAAK,CAAC;wCAC7E,qBAAM,OAAO,CAAC,MAAM,CAAC,OAAO,EAAE,gBAAgB,CAAC,EAAA;;wCAA/C,SAA+C,CAAC;;;;;6BAEvD,CAAC,CAAC,EAAE,cAAc,CAAC,EAAA;;oBA1BpB,SA0BoB,CAAC;;;;;CACxB;AAvDD,oCAuDC"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -10,5 +10,12 @@ 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
|
+
__exportStar(require("./config"), exports);
|
|
15
|
+
__exportStar(require("./consume"), exports);
|
|
13
16
|
__exportStar(require("./connection"), exports);
|
|
17
|
+
__exportStar(require("./message"), exports);
|
|
18
|
+
__exportStar(require("./publish"), exports);
|
|
19
|
+
var publish_1 = require("./publish");
|
|
20
|
+
Object.defineProperty(exports, "publishMessage", { enumerable: true, get: function () { return publish_1.publishMessage; } });
|
|
14
21
|
//# 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;AAC1B,qCAAyC;AAAjC,yGAAA,cAAc,OAAA"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildMessage = void 0;
|
|
4
|
+
var uuid_1 = require("uuid");
|
|
5
|
+
function buildMessage(context) {
|
|
6
|
+
var _a, _b, _c, _d;
|
|
7
|
+
return {
|
|
8
|
+
id: (_a = context.id) !== null && _a !== void 0 ? _a : (0, uuid_1.v4)(),
|
|
9
|
+
type: context.type,
|
|
10
|
+
options: (_b = context.options) !== null && _b !== void 0 ? _b : {},
|
|
11
|
+
data: (_c = context.data) !== null && _c !== void 0 ? _c : {},
|
|
12
|
+
metadata: (_d = context.metadata) !== null && _d !== void 0 ? _d : {}
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
exports.buildMessage = buildMessage;
|
|
16
|
+
//# sourceMappingURL=build.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build.js","sourceRoot":"","sources":["../../src/message/build.ts"],"names":[],"mappings":";;;AAAA,6BAAwB;AAGxB,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"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
__exportStar(require("./build"), exports);
|
|
14
|
+
__exportStar(require("./type"), exports);
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/message/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,0CAAwB;AACxB,yCAAuB"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Channel, Connection, MessageFields, MessageProperties, Options } from "amqplib";
|
|
2
|
+
export interface MessageOptions {
|
|
3
|
+
/**
|
|
4
|
+
* Routing key for message broker.
|
|
5
|
+
*/
|
|
6
|
+
routingKey?: string;
|
|
7
|
+
/**
|
|
8
|
+
* Override default publish options.
|
|
9
|
+
*/
|
|
10
|
+
publish?: Options.Publish;
|
|
11
|
+
}
|
|
12
|
+
export declare type Message = {
|
|
13
|
+
/**
|
|
14
|
+
* Routing information for amqp library.
|
|
15
|
+
* This property will be removed, before it is passed to the message queue.
|
|
16
|
+
*/
|
|
17
|
+
options?: MessageOptions;
|
|
18
|
+
/**
|
|
19
|
+
*
|
|
20
|
+
* Default: <generated uuid>
|
|
21
|
+
*/
|
|
22
|
+
id: string;
|
|
23
|
+
/**
|
|
24
|
+
* Event- or Command-name.
|
|
25
|
+
*/
|
|
26
|
+
type: string;
|
|
27
|
+
/**
|
|
28
|
+
* Metadata object to provide details for the message broker.
|
|
29
|
+
*
|
|
30
|
+
* Default: {}
|
|
31
|
+
*/
|
|
32
|
+
metadata: Record<string, any>;
|
|
33
|
+
/**
|
|
34
|
+
* The message data.
|
|
35
|
+
*
|
|
36
|
+
* Default: {}
|
|
37
|
+
*/
|
|
38
|
+
data: Record<string, any>;
|
|
39
|
+
};
|
|
40
|
+
export declare type BuildMessageContext = Pick<Message, 'type'> & Partial<Pick<Message, 'id' | 'options' | 'data' | 'metadata'>>;
|
|
41
|
+
export declare type MessageContext = {
|
|
42
|
+
channel: Channel;
|
|
43
|
+
connection: Connection;
|
|
44
|
+
messageFields?: MessageFields;
|
|
45
|
+
messageProperties?: MessageProperties;
|
|
46
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.js","sourceRoot":"","sources":["../../src/message/type.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
__exportStar(require("./utils"), exports);
|
|
14
|
+
__exportStar(require("./type"), exports);
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/publish/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,0CAAwB;AACxB,yCAAuB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.js","sourceRoot":"","sources":["../../src/publish/type.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
+
function step(op) {
|
|
27
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
+
while (_) try {
|
|
29
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
+
switch (op[0]) {
|
|
32
|
+
case 0: case 1: t = op; break;
|
|
33
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
+
default:
|
|
37
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
+
if (t[2]) _.ops.pop();
|
|
42
|
+
_.trys.pop(); continue;
|
|
43
|
+
}
|
|
44
|
+
op = body.call(thisArg, _);
|
|
45
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
50
|
+
var t = {};
|
|
51
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
52
|
+
t[p] = s[p];
|
|
53
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
54
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
55
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
56
|
+
t[p[i]] = s[p[i]];
|
|
57
|
+
}
|
|
58
|
+
return t;
|
|
59
|
+
};
|
|
60
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
61
|
+
exports.publishMessage = void 0;
|
|
62
|
+
var config_1 = require("../config");
|
|
63
|
+
var utils_1 = require("../utils");
|
|
64
|
+
/* istanbul ignore next */
|
|
65
|
+
function publishMessage(message, options) {
|
|
66
|
+
var _a, _b, _c, _d;
|
|
67
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
68
|
+
var messageOptions, messagePayload, buffer, config, channel, publishOptions;
|
|
69
|
+
return __generator(this, function (_e) {
|
|
70
|
+
switch (_e.label) {
|
|
71
|
+
case 0:
|
|
72
|
+
messageOptions = message.options, messagePayload = __rest(message, ["options"]);
|
|
73
|
+
buffer = Buffer.from(JSON.stringify(messagePayload));
|
|
74
|
+
options !== null && options !== void 0 ? options : (options = {});
|
|
75
|
+
config = (0, config_1.getConfig)(options.alias);
|
|
76
|
+
return [4 /*yield*/, (0, utils_1.createChannel)(config)];
|
|
77
|
+
case 1:
|
|
78
|
+
channel = (_e.sent()).channel;
|
|
79
|
+
publishOptions = __assign(__assign(__assign({}, ((_b = (_a = config.publish) === null || _a === void 0 ? void 0 : _a.options) !== null && _b !== void 0 ? _b : {})), ((_c = messageOptions.publish) !== null && _c !== void 0 ? _c : {})), ((_d = options.options) !== null && _d !== void 0 ? _d : {}));
|
|
80
|
+
channel.publish(config.exchange.name, messageOptions.routingKey, buffer, publishOptions);
|
|
81
|
+
return [2 /*return*/];
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
exports.publishMessage = publishMessage;
|
|
87
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/publish/utils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,oCAA4C;AAE5C,kCAAuC;AAGvC,0BAA0B;AAC1B,SAAsB,cAAc,CAChC,OAAgB,EAChB,OAAwB;;;;;;;oBAEV,cAAc,GAAuB,OAAO,QAA9B,EAAK,cAAc,UAAI,OAAO,EAAtD,WAA4C,CAAD,CAAY;oBAErD,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;oBAC9B,qBAAM,IAAA,qBAAa,EAAC,MAAM,CAAC,EAAA;;oBAAtC,OAAO,GAAI,CAAA,SAA2B,CAAA,QAA/B;oBAER,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,CAAA;oBAED,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
ADDED
package/dist/utils.js
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
+
function step(op) {
|
|
27
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
+
while (_) try {
|
|
29
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
+
switch (op[0]) {
|
|
32
|
+
case 0: case 1: t = op; break;
|
|
33
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
+
default:
|
|
37
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
+
if (t[2]) _.ops.pop();
|
|
42
|
+
_.trys.pop(); continue;
|
|
43
|
+
}
|
|
44
|
+
op = body.call(thisArg, _);
|
|
45
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
|
+
exports.createChannel = void 0;
|
|
51
|
+
var config_1 = require("./config");
|
|
52
|
+
var connection_1 = require("./connection");
|
|
53
|
+
/* istanbul ignore next */
|
|
54
|
+
function createChannel(key) {
|
|
55
|
+
var _a, _b;
|
|
56
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
57
|
+
var config, connection, channel, exchangeOptions;
|
|
58
|
+
return __generator(this, function (_c) {
|
|
59
|
+
switch (_c.label) {
|
|
60
|
+
case 0:
|
|
61
|
+
config = (0, config_1.getConfig)(key);
|
|
62
|
+
return [4 /*yield*/, (0, connection_1.useConnection)(config.alias)];
|
|
63
|
+
case 1:
|
|
64
|
+
connection = _c.sent();
|
|
65
|
+
return [4 /*yield*/, connection.createChannel()];
|
|
66
|
+
case 2:
|
|
67
|
+
channel = _c.sent();
|
|
68
|
+
exchangeOptions = __assign({ durable: true }, ((_b = (_a = config.exchange) === null || _a === void 0 ? void 0 : _a.options) !== null && _b !== void 0 ? _b : {}));
|
|
69
|
+
return [4 /*yield*/, channel.assertExchange(config.exchange.name, config.exchange.type, exchangeOptions)];
|
|
70
|
+
case 3:
|
|
71
|
+
_c.sent();
|
|
72
|
+
return [2 /*return*/, {
|
|
73
|
+
channel: channel,
|
|
74
|
+
connection: connection
|
|
75
|
+
}];
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
exports.createChannel = createChannel;
|
|
81
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,mCAA2C;AAC3C,2CAA2C;AAE3C,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,EAAE,OAAO;4BAChB,UAAU,EAAE,UAAU;yBACzB,EAAC;;;;CACL;AApBD,sCAoBC"}
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare type ConnectionAlias = 'default' | string;
|