amqpx 0.0.0 → 1.0.0
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/LICENSE +8 -0
- package/README.md +63 -0
- package/dist/cjs/channel/channel-implementation.d.ts +30 -0
- package/dist/cjs/channel/channel-implementation.js +212 -0
- package/dist/cjs/channel/channel.d.ts +149 -0
- package/dist/cjs/channel/channel.js +2 -0
- package/dist/cjs/channel/index.d.ts +2 -0
- package/dist/cjs/channel/index.js +5 -0
- package/dist/cjs/channel/types.d.ts +12 -0
- package/dist/cjs/channel/types.js +2 -0
- package/dist/cjs/connection/connection-implementation.d.ts +35 -0
- package/dist/cjs/connection/connection-implementation.js +195 -0
- package/dist/cjs/connection/connection.d.ts +143 -0
- package/dist/cjs/connection/connection.js +11 -0
- package/dist/cjs/connection/index.d.ts +2 -0
- package/dist/cjs/connection/index.js +8 -0
- package/dist/cjs/consumer/base-consumer.d.ts +33 -0
- package/dist/cjs/consumer/base-consumer.js +85 -0
- package/dist/cjs/consumer/batch-consumer-implementation.d.ts +25 -0
- package/dist/cjs/consumer/batch-consumer-implementation.js +313 -0
- package/dist/cjs/consumer/batch-consumer.d.ts +39 -0
- package/dist/cjs/consumer/batch-consumer.js +2 -0
- package/dist/cjs/consumer/consumer-implementation.d.ts +12 -0
- package/dist/cjs/consumer/consumer-implementation.js +105 -0
- package/dist/cjs/consumer/consumer.d.ts +40 -0
- package/dist/cjs/consumer/consumer.js +4 -0
- package/dist/cjs/consumer/index.d.ts +5 -0
- package/dist/cjs/consumer/index.js +10 -0
- package/dist/cjs/consumer/types.d.ts +194 -0
- package/dist/cjs/consumer/types.js +34 -0
- package/dist/cjs/errors.d.ts +22 -0
- package/dist/cjs/errors.js +13 -0
- package/dist/cjs/exchange/default-exchange.d.ts +10 -0
- package/dist/cjs/exchange/default-exchange.js +14 -0
- package/dist/cjs/exchange/exchange-implementation.d.ts +24 -0
- package/dist/cjs/exchange/exchange-implementation.js +159 -0
- package/dist/cjs/exchange/exchange.d.ts +63 -0
- package/dist/cjs/exchange/exchange.js +2 -0
- package/dist/cjs/exchange/index.d.ts +3 -0
- package/dist/cjs/exchange/index.js +5 -0
- package/dist/cjs/exchange/types.d.ts +58 -0
- package/dist/cjs/exchange/types.js +8 -0
- package/dist/cjs/extensions/jest/index.d.ts +7 -0
- package/dist/cjs/extensions/jest/index.js +23 -0
- package/dist/cjs/extensions/jest/test-batch-consumer.d.ts +48 -0
- package/dist/cjs/extensions/jest/test-batch-consumer.js +56 -0
- package/dist/cjs/extensions/jest/test-channel.d.ts +71 -0
- package/dist/cjs/extensions/jest/test-channel.js +75 -0
- package/dist/cjs/extensions/jest/test-connection.d.ts +38 -0
- package/dist/cjs/extensions/jest/test-connection.js +29 -0
- package/dist/cjs/extensions/jest/test-consumer.d.ts +49 -0
- package/dist/cjs/extensions/jest/test-consumer.js +54 -0
- package/dist/cjs/extensions/jest/test-exchange.d.ts +26 -0
- package/dist/cjs/extensions/jest/test-exchange.js +16 -0
- package/dist/cjs/extensions/jest/test-producer.d.ts +33 -0
- package/dist/cjs/extensions/jest/test-producer.js +17 -0
- package/dist/cjs/extensions/jest/test-queue.d.ts +25 -0
- package/dist/cjs/extensions/jest/test-queue.js +17 -0
- package/dist/cjs/extensions/vitest/index.d.ts +7 -0
- package/dist/cjs/extensions/vitest/index.js +23 -0
- package/dist/cjs/extensions/vitest/test-batch-consumer.d.ts +48 -0
- package/dist/cjs/extensions/vitest/test-batch-consumer.js +56 -0
- package/dist/cjs/extensions/vitest/test-channel.d.ts +71 -0
- package/dist/cjs/extensions/vitest/test-channel.js +77 -0
- package/dist/cjs/extensions/vitest/test-connection.d.ts +38 -0
- package/dist/cjs/extensions/vitest/test-connection.js +29 -0
- package/dist/cjs/extensions/vitest/test-consumer.d.ts +49 -0
- package/dist/cjs/extensions/vitest/test-consumer.js +54 -0
- package/dist/cjs/extensions/vitest/test-exchange.d.ts +26 -0
- package/dist/cjs/extensions/vitest/test-exchange.js +16 -0
- package/dist/cjs/extensions/vitest/test-producer.d.ts +34 -0
- package/dist/cjs/extensions/vitest/test-producer.js +18 -0
- package/dist/cjs/extensions/vitest/test-queue.d.ts +25 -0
- package/dist/cjs/extensions/vitest/test-queue.js +17 -0
- package/dist/cjs/extensions/zod/index.d.ts +2 -0
- package/dist/cjs/extensions/zod/index.js +18 -0
- package/dist/cjs/extensions/zod/zod-validated-batch-consumer.d.ts +57 -0
- package/dist/cjs/extensions/zod/zod-validated-batch-consumer.js +46 -0
- package/dist/cjs/extensions/zod/zod-validated-consumer.d.ts +55 -0
- package/dist/cjs/extensions/zod/zod-validated-consumer.js +42 -0
- package/dist/cjs/graceful-shutdown/index.d.ts +1 -0
- package/dist/cjs/graceful-shutdown/index.js +17 -0
- package/dist/cjs/graceful-shutdown/rabbit-closer.d.ts +29 -0
- package/dist/cjs/graceful-shutdown/rabbit-closer.js +42 -0
- package/dist/cjs/index.d.ts +11 -0
- package/dist/cjs/index.js +51 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/predefined.d.ts +62 -0
- package/dist/cjs/predefined.js +27 -0
- package/dist/cjs/producer/index.d.ts +3 -0
- package/dist/cjs/producer/index.js +5 -0
- package/dist/cjs/producer/producer-implementation.d.ts +18 -0
- package/dist/cjs/producer/producer-implementation.js +109 -0
- package/dist/cjs/producer/producer.d.ts +44 -0
- package/dist/cjs/producer/producer.js +2 -0
- package/dist/cjs/producer/types.d.ts +70 -0
- package/dist/cjs/producer/types.js +13 -0
- package/dist/cjs/queue/index.d.ts +3 -0
- package/dist/cjs/queue/index.js +5 -0
- package/dist/cjs/queue/queue-implementation.d.ts +21 -0
- package/dist/cjs/queue/queue-implementation.js +91 -0
- package/dist/cjs/queue/queue.d.ts +51 -0
- package/dist/cjs/queue/queue.js +2 -0
- package/dist/cjs/queue/types.d.ts +25 -0
- package/dist/cjs/queue/types.js +2 -0
- package/dist/cjs/retry/default-retry-strategy.d.ts +9 -0
- package/dist/cjs/retry/default-retry-strategy.js +8 -0
- package/dist/cjs/retry/index.d.ts +4 -0
- package/dist/cjs/retry/index.js +45 -0
- package/dist/cjs/retry/retry-implementation.d.ts +18 -0
- package/dist/cjs/retry/retry-implementation.js +44 -0
- package/dist/cjs/retry/retry-strategy.d.ts +28 -0
- package/dist/cjs/retry/retry-strategy.js +10 -0
- package/dist/cjs/retry/time-strategies.d.ts +45 -0
- package/dist/cjs/retry/time-strategies.js +32 -0
- package/dist/cjs/types.d.ts +30 -0
- package/dist/cjs/types.js +9 -0
- package/dist/cjs/utils.d.ts +11 -0
- package/dist/cjs/utils.js +83 -0
- package/dist/esm/channel/channel-implementation.d.ts +30 -0
- package/dist/esm/channel/channel-implementation.js +208 -0
- package/dist/esm/channel/channel.d.ts +149 -0
- package/dist/esm/channel/channel.js +1 -0
- package/dist/esm/channel/index.d.ts +2 -0
- package/dist/esm/channel/index.js +1 -0
- package/dist/esm/channel/types.d.ts +12 -0
- package/dist/esm/channel/types.js +1 -0
- package/dist/esm/connection/connection-implementation.d.ts +35 -0
- package/dist/esm/connection/connection-implementation.js +157 -0
- package/dist/esm/connection/connection.d.ts +143 -0
- package/dist/esm/connection/connection.js +8 -0
- package/dist/esm/connection/index.d.ts +2 -0
- package/dist/esm/connection/index.js +2 -0
- package/dist/esm/consumer/base-consumer.d.ts +33 -0
- package/dist/esm/consumer/base-consumer.js +81 -0
- package/dist/esm/consumer/batch-consumer-implementation.d.ts +25 -0
- package/dist/esm/consumer/batch-consumer-implementation.js +309 -0
- package/dist/esm/consumer/batch-consumer.d.ts +39 -0
- package/dist/esm/consumer/batch-consumer.js +1 -0
- package/dist/esm/consumer/consumer-implementation.d.ts +12 -0
- package/dist/esm/consumer/consumer-implementation.js +101 -0
- package/dist/esm/consumer/consumer.d.ts +40 -0
- package/dist/esm/consumer/consumer.js +1 -0
- package/dist/esm/consumer/index.d.ts +5 -0
- package/dist/esm/consumer/index.js +3 -0
- package/dist/esm/consumer/types.d.ts +194 -0
- package/dist/esm/consumer/types.js +31 -0
- package/dist/esm/errors.d.ts +22 -0
- package/dist/esm/errors.js +8 -0
- package/dist/esm/exchange/default-exchange.d.ts +10 -0
- package/dist/esm/exchange/default-exchange.js +10 -0
- package/dist/esm/exchange/exchange-implementation.d.ts +24 -0
- package/dist/esm/exchange/exchange-implementation.js +152 -0
- package/dist/esm/exchange/exchange.d.ts +63 -0
- package/dist/esm/exchange/exchange.js +1 -0
- package/dist/esm/exchange/index.d.ts +3 -0
- package/dist/esm/exchange/index.js +1 -0
- package/dist/esm/exchange/types.d.ts +58 -0
- package/dist/esm/exchange/types.js +5 -0
- package/dist/esm/extensions/jest/index.d.ts +7 -0
- package/dist/esm/extensions/jest/index.js +7 -0
- package/dist/esm/extensions/jest/test-batch-consumer.d.ts +48 -0
- package/dist/esm/extensions/jest/test-batch-consumer.js +52 -0
- package/dist/esm/extensions/jest/test-channel.d.ts +71 -0
- package/dist/esm/extensions/jest/test-channel.js +71 -0
- package/dist/esm/extensions/jest/test-connection.d.ts +38 -0
- package/dist/esm/extensions/jest/test-connection.js +25 -0
- package/dist/esm/extensions/jest/test-consumer.d.ts +49 -0
- package/dist/esm/extensions/jest/test-consumer.js +50 -0
- package/dist/esm/extensions/jest/test-exchange.d.ts +26 -0
- package/dist/esm/extensions/jest/test-exchange.js +12 -0
- package/dist/esm/extensions/jest/test-producer.d.ts +33 -0
- package/dist/esm/extensions/jest/test-producer.js +13 -0
- package/dist/esm/extensions/jest/test-queue.d.ts +25 -0
- package/dist/esm/extensions/jest/test-queue.js +13 -0
- package/dist/esm/extensions/vitest/index.d.ts +7 -0
- package/dist/esm/extensions/vitest/index.js +7 -0
- package/dist/esm/extensions/vitest/test-batch-consumer.d.ts +48 -0
- package/dist/esm/extensions/vitest/test-batch-consumer.js +52 -0
- package/dist/esm/extensions/vitest/test-channel.d.ts +71 -0
- package/dist/esm/extensions/vitest/test-channel.js +73 -0
- package/dist/esm/extensions/vitest/test-connection.d.ts +38 -0
- package/dist/esm/extensions/vitest/test-connection.js +25 -0
- package/dist/esm/extensions/vitest/test-consumer.d.ts +49 -0
- package/dist/esm/extensions/vitest/test-consumer.js +50 -0
- package/dist/esm/extensions/vitest/test-exchange.d.ts +26 -0
- package/dist/esm/extensions/vitest/test-exchange.js +12 -0
- package/dist/esm/extensions/vitest/test-producer.d.ts +34 -0
- package/dist/esm/extensions/vitest/test-producer.js +14 -0
- package/dist/esm/extensions/vitest/test-queue.d.ts +25 -0
- package/dist/esm/extensions/vitest/test-queue.js +13 -0
- package/dist/esm/extensions/zod/index.d.ts +2 -0
- package/dist/esm/extensions/zod/index.js +2 -0
- package/dist/esm/extensions/zod/zod-validated-batch-consumer.d.ts +57 -0
- package/dist/esm/extensions/zod/zod-validated-batch-consumer.js +42 -0
- package/dist/esm/extensions/zod/zod-validated-consumer.d.ts +55 -0
- package/dist/esm/extensions/zod/zod-validated-consumer.js +38 -0
- package/dist/esm/graceful-shutdown/index.d.ts +1 -0
- package/dist/esm/graceful-shutdown/index.js +1 -0
- package/dist/esm/graceful-shutdown/rabbit-closer.d.ts +29 -0
- package/dist/esm/graceful-shutdown/rabbit-closer.js +38 -0
- package/dist/esm/index.d.ts +11 -0
- package/dist/esm/index.js +11 -0
- package/dist/esm/package.json +1 -0
- package/dist/esm/predefined.d.ts +62 -0
- package/dist/esm/predefined.js +18 -0
- package/dist/esm/producer/index.d.ts +3 -0
- package/dist/esm/producer/index.js +1 -0
- package/dist/esm/producer/producer-implementation.d.ts +18 -0
- package/dist/esm/producer/producer-implementation.js +105 -0
- package/dist/esm/producer/producer.d.ts +44 -0
- package/dist/esm/producer/producer.js +1 -0
- package/dist/esm/producer/types.d.ts +70 -0
- package/dist/esm/producer/types.js +10 -0
- package/dist/esm/queue/index.d.ts +3 -0
- package/dist/esm/queue/index.js +1 -0
- package/dist/esm/queue/queue-implementation.d.ts +21 -0
- package/dist/esm/queue/queue-implementation.js +87 -0
- package/dist/esm/queue/queue.d.ts +51 -0
- package/dist/esm/queue/queue.js +1 -0
- package/dist/esm/queue/types.d.ts +25 -0
- package/dist/esm/queue/types.js +1 -0
- package/dist/esm/retry/default-retry-strategy.d.ts +9 -0
- package/dist/esm/retry/default-retry-strategy.js +5 -0
- package/dist/esm/retry/index.d.ts +4 -0
- package/dist/esm/retry/index.js +4 -0
- package/dist/esm/retry/retry-implementation.d.ts +18 -0
- package/dist/esm/retry/retry-implementation.js +40 -0
- package/dist/esm/retry/retry-strategy.d.ts +28 -0
- package/dist/esm/retry/retry-strategy.js +6 -0
- package/dist/esm/retry/time-strategies.d.ts +45 -0
- package/dist/esm/retry/time-strategies.js +24 -0
- package/dist/esm/types.d.ts +30 -0
- package/dist/esm/types.js +6 -0
- package/dist/esm/utils.d.ts +11 -0
- package/dist/esm/utils.js +72 -0
- package/package.json +101 -6
- package/.claude/settings.local.json +0 -13
- package/.idea/amqp-oop.iml +0 -15
- package/.idea/aws.xml +0 -11
- package/.idea/inspectionProfiles/Project_Default.xml +0 -6
- package/.idea/jsLibraryMappings.xml +0 -6
- package/.idea/jsLinters/eslint.xml +0 -6
- package/.idea/modules.xml +0 -8
- package/.idea/vcs.xml +0 -6
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
11
|
+
var t = {};
|
|
12
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
13
|
+
t[p] = s[p];
|
|
14
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
15
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
16
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
17
|
+
t[p[i]] = s[p[i]];
|
|
18
|
+
}
|
|
19
|
+
return t;
|
|
20
|
+
};
|
|
21
|
+
import { debuglog } from 'util';
|
|
22
|
+
import { EventEmitter } from 'events';
|
|
23
|
+
import { performance } from 'perf_hooks';
|
|
24
|
+
import { ExchangeImplementation } from '../exchange';
|
|
25
|
+
import { QueueImplementation } from '../queue';
|
|
26
|
+
import { DEFAULT_RETRY_STRATEGY, retryLoop } from '../retry';
|
|
27
|
+
import { DrainError } from '../errors';
|
|
28
|
+
import { errToMessage, LIB_NAME, sleepPromise, swallowError } from '../utils';
|
|
29
|
+
const debug = debuglog(`${LIB_NAME}:channel`);
|
|
30
|
+
export class ChannelImplementation extends EventEmitter {
|
|
31
|
+
constructor(connection, publishConfirm) {
|
|
32
|
+
super();
|
|
33
|
+
this.connection = connection;
|
|
34
|
+
this.closeHandler = null;
|
|
35
|
+
this.drainPromise = null;
|
|
36
|
+
this.wrapper = {
|
|
37
|
+
channel: null,
|
|
38
|
+
isConfirmed: publishConfirm,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
connect() {
|
|
42
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
43
|
+
if (this.wrapper.channel) {
|
|
44
|
+
yield this.wrapper.channel;
|
|
45
|
+
return this;
|
|
46
|
+
}
|
|
47
|
+
this.wrapper.channel = (() => __awaiter(this, void 0, void 0, function* () {
|
|
48
|
+
try {
|
|
49
|
+
debug('connecting confirmed=%s', this.wrapper.isConfirmed);
|
|
50
|
+
const connection = yield this.connection.native();
|
|
51
|
+
const channel = yield (this.wrapper.isConfirmed ? connection.createConfirmChannel() : connection.createChannel());
|
|
52
|
+
debug('connected confirmed=%s', this.wrapper.isConfirmed);
|
|
53
|
+
channel.on('error', error => {
|
|
54
|
+
this.wrapper.channel = null;
|
|
55
|
+
debug('native-error error=%s', error === null || error === void 0 ? void 0 : error.message);
|
|
56
|
+
this.emit('error', error);
|
|
57
|
+
});
|
|
58
|
+
channel.on(`close`, () => __awaiter(this, void 0, void 0, function* () {
|
|
59
|
+
this.wrapper.channel = null;
|
|
60
|
+
debug('native-close');
|
|
61
|
+
this.emit('close');
|
|
62
|
+
}));
|
|
63
|
+
channel.on('drain', () => {
|
|
64
|
+
debug('native-drain');
|
|
65
|
+
this.emit('drain');
|
|
66
|
+
});
|
|
67
|
+
return channel;
|
|
68
|
+
}
|
|
69
|
+
catch (err) {
|
|
70
|
+
this.wrapper.channel = null;
|
|
71
|
+
throw err;
|
|
72
|
+
}
|
|
73
|
+
}))();
|
|
74
|
+
yield this.wrapper.channel;
|
|
75
|
+
return this;
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
close() {
|
|
79
|
+
return __awaiter(this, arguments, void 0, function* (timeout = 30000) {
|
|
80
|
+
var _a;
|
|
81
|
+
if (!this.wrapper.channel)
|
|
82
|
+
return;
|
|
83
|
+
(_a = this.closeHandler) !== null && _a !== void 0 ? _a : (this.closeHandler = (() => __awaiter(this, void 0, void 0, function* () {
|
|
84
|
+
try {
|
|
85
|
+
debug('closing');
|
|
86
|
+
const wrapper = {
|
|
87
|
+
isConfirmed: this.wrapper.isConfirmed,
|
|
88
|
+
channel: yield this.wrapper.channel,
|
|
89
|
+
};
|
|
90
|
+
if (!wrapper.channel)
|
|
91
|
+
throw new Error('Internal error: channel is empty but app attempted to close it');
|
|
92
|
+
const doClose = (arg) => __awaiter(this, void 0, void 0, function* () {
|
|
93
|
+
if (!arg.channel)
|
|
94
|
+
return;
|
|
95
|
+
if (wrapper.isConfirmed)
|
|
96
|
+
yield swallowError(arg.channel.waitForConfirms());
|
|
97
|
+
yield swallowError(arg.channel.close());
|
|
98
|
+
});
|
|
99
|
+
const abort = new AbortController();
|
|
100
|
+
yield Promise.race([
|
|
101
|
+
doClose(wrapper).then(() => abort.abort()),
|
|
102
|
+
sleepPromise(timeout).then(() => {
|
|
103
|
+
if (!abort.signal.aborted)
|
|
104
|
+
throw new Error('Channel close timed out');
|
|
105
|
+
}),
|
|
106
|
+
]);
|
|
107
|
+
debug('closed');
|
|
108
|
+
}
|
|
109
|
+
finally {
|
|
110
|
+
this.closeHandler = null;
|
|
111
|
+
this.wrapper.channel = null;
|
|
112
|
+
}
|
|
113
|
+
}))());
|
|
114
|
+
return this.closeHandler;
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
createExchange(name, type, options) {
|
|
118
|
+
return new ExchangeImplementation(this, name, type, options).assert();
|
|
119
|
+
}
|
|
120
|
+
createQueue(name, options) {
|
|
121
|
+
return new QueueImplementation(this, name, options).assert();
|
|
122
|
+
}
|
|
123
|
+
checkQueue(name) {
|
|
124
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
125
|
+
const nativeChannel = yield this.native();
|
|
126
|
+
return nativeChannel.checkQueue(name);
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
native() {
|
|
130
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
131
|
+
yield this.connect();
|
|
132
|
+
if (this.wrapper.channel)
|
|
133
|
+
return this.wrapper.channel;
|
|
134
|
+
throw new Error(`Channel not created`);
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
publish(exchange, routingKey, content, optionsArgs) {
|
|
138
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
139
|
+
debug('publish exchange=%s routing-key=%s confirmed=%s', exchange, routingKey, this.wrapper.isConfirmed);
|
|
140
|
+
const { drainTimeout, retryStrategy = DEFAULT_RETRY_STRATEGY } = optionsArgs, options = __rest(optionsArgs, ["drainTimeout", "retryStrategy"]);
|
|
141
|
+
while (true) {
|
|
142
|
+
const native = yield this.native();
|
|
143
|
+
if (this.drainPromise)
|
|
144
|
+
yield this.drainPromise;
|
|
145
|
+
let publishResult;
|
|
146
|
+
if (!this.wrapper.isConfirmed) {
|
|
147
|
+
const channel = native;
|
|
148
|
+
publishResult = channel.publish(exchange, routingKey, content, options);
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
const channel = native;
|
|
152
|
+
publishResult = yield retryLoop(retryStrategy, () => new Promise((resolve, reject) => {
|
|
153
|
+
const status = channel.publish(exchange, routingKey, content, options, err => {
|
|
154
|
+
err ? reject(err) : resolve(status);
|
|
155
|
+
});
|
|
156
|
+
}), err => {
|
|
157
|
+
debug('publish-nacked error=%s', errToMessage(err));
|
|
158
|
+
return errToMessage(err) === 'message nacked';
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
if (publishResult) {
|
|
162
|
+
debug('publish-success exchange=%s routing-key=%s', exchange, routingKey);
|
|
163
|
+
return this.wrapper.isConfirmed;
|
|
164
|
+
}
|
|
165
|
+
if (!this.drainPromise) {
|
|
166
|
+
const drainStart = performance.now();
|
|
167
|
+
debug('backpressure-detected exchange=%s routing-key=%s', exchange, routingKey);
|
|
168
|
+
this.drainPromise = new Promise((resolve, reject) => {
|
|
169
|
+
let timeoutHandler;
|
|
170
|
+
const drainHandler = () => {
|
|
171
|
+
clearTimeout(timeoutHandler);
|
|
172
|
+
debug('drain-cleared after=%dms', performance.now() - drainStart);
|
|
173
|
+
this.drainPromise = null;
|
|
174
|
+
resolve();
|
|
175
|
+
};
|
|
176
|
+
this.once('drain', drainHandler);
|
|
177
|
+
this.once('close', drainHandler);
|
|
178
|
+
timeoutHandler = setTimeout(() => __awaiter(this, void 0, void 0, function* () {
|
|
179
|
+
this.removeListener('drain', drainHandler);
|
|
180
|
+
this.drainPromise = null;
|
|
181
|
+
debug('drain-timeout exchange=%s routing-key=%s timeout=%dms', exchange, routingKey, drainTimeout);
|
|
182
|
+
reject(new DrainError('Rabbit drain timeout'));
|
|
183
|
+
void native.close();
|
|
184
|
+
}), drainTimeout);
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
createProducerForQueue(queue, options = {}) {
|
|
191
|
+
return queue.createProducer(Object.assign({ channel: this }, options));
|
|
192
|
+
}
|
|
193
|
+
createProducerForExchange(exchange, options = {}) {
|
|
194
|
+
return exchange.createProducer(Object.assign({ channel: this }, options));
|
|
195
|
+
}
|
|
196
|
+
createConsumerForQueue(queue, options) {
|
|
197
|
+
return queue.createConsumer(Object.assign({ channel: this }, options));
|
|
198
|
+
}
|
|
199
|
+
createConsumerForExchange(exchange, options, queueOptions) {
|
|
200
|
+
return exchange.createConsumer(Object.assign({ channel: this }, options), queueOptions);
|
|
201
|
+
}
|
|
202
|
+
createBatchConsumerForQueue(queue, options) {
|
|
203
|
+
return queue.createBatchConsumer(Object.assign({ channel: this }, options));
|
|
204
|
+
}
|
|
205
|
+
createBatchConsumerForExchange(exchange, options, queueOptions) {
|
|
206
|
+
return exchange.createBatchConsumer(Object.assign({ channel: this }, options), queueOptions);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { EventEmitter } from 'events';
|
|
2
|
+
import * as amqp from 'amqplib';
|
|
3
|
+
import { Replies } from 'amqplib';
|
|
4
|
+
import { Queue, QueueOptions } from '../queue';
|
|
5
|
+
import { ExchangeTypes, Exchange, ExchangeConsumerQueueOptions, ExchangeConsumerOptions, ExchangeBatchConsumerOptions, ExchangeOptions } from '../exchange';
|
|
6
|
+
import { Producer, ProducerOptions } from '../producer';
|
|
7
|
+
import { ConsumerOptions, Consumer, BatchConsumerOptions, BatchConsumer } from '../consumer';
|
|
8
|
+
import { Connection } from '../connection';
|
|
9
|
+
import { ChannelPublishOptions } from './types';
|
|
10
|
+
/**
|
|
11
|
+
* Events emitted by a {@link Channel}.
|
|
12
|
+
*/
|
|
13
|
+
export interface ChannelEventMap {
|
|
14
|
+
/**
|
|
15
|
+
* Emitted when the underlying amqplib channel encounters an error.
|
|
16
|
+
*/
|
|
17
|
+
error: [err: unknown];
|
|
18
|
+
/**
|
|
19
|
+
* Emitted when the underlying amqplib channel is closed.
|
|
20
|
+
*/
|
|
21
|
+
close: [];
|
|
22
|
+
/**
|
|
23
|
+
* Emitted when the internal write buffer drains after backpressure.
|
|
24
|
+
*/
|
|
25
|
+
drain: [];
|
|
26
|
+
}
|
|
27
|
+
export interface Channel extends EventEmitter<ChannelEventMap> {
|
|
28
|
+
/**
|
|
29
|
+
* The {@link Connection} that owns this channel.
|
|
30
|
+
*/
|
|
31
|
+
get connection(): Connection;
|
|
32
|
+
/**
|
|
33
|
+
* Open the underlying amqplib channel.
|
|
34
|
+
* Must be called before any other operation.
|
|
35
|
+
* Subsequent calls are no-ops if the channel is already open.
|
|
36
|
+
*/
|
|
37
|
+
connect(): Promise<Channel>;
|
|
38
|
+
/**
|
|
39
|
+
* Close the underlying amqplib channel.
|
|
40
|
+
* For confirm channels, waits for all pending confirmations before closing.
|
|
41
|
+
* @param timeout - Maximum milliseconds to wait for pending confirmations before closing.
|
|
42
|
+
* Throws `'Channel close timed out'` if exceeded. Waits 30s when omitted.
|
|
43
|
+
*/
|
|
44
|
+
close(timeout?: number): Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
* Assert an exchange on the broker and return an {@link Exchange} handle.
|
|
47
|
+
*
|
|
48
|
+
* @param name - Exchange name.
|
|
49
|
+
* @param type - Exchange type (direct, fanout, topic, headers, …).
|
|
50
|
+
* @param options - Optional exchange assertion options.
|
|
51
|
+
*/
|
|
52
|
+
createExchange(name: string, type: ExchangeTypes, options?: ExchangeOptions): Promise<Exchange>;
|
|
53
|
+
/**
|
|
54
|
+
* Assert a queue on the broker and return a {@link Queue} handle.
|
|
55
|
+
*
|
|
56
|
+
* @param name - Queue name.
|
|
57
|
+
* @param options - Optional queue assertion options.
|
|
58
|
+
*/
|
|
59
|
+
createQueue(name: string, options?: QueueOptions): Promise<Queue>;
|
|
60
|
+
/**
|
|
61
|
+
* Check whether a queue exists on the broker without asserting it.
|
|
62
|
+
* Resolves with queue metadata; rejects if the queue does not exist.
|
|
63
|
+
*
|
|
64
|
+
* @param name - Queue name to inspect.
|
|
65
|
+
*/
|
|
66
|
+
checkQueue(name: string): Promise<Replies.AssertQueue>;
|
|
67
|
+
/**
|
|
68
|
+
* Returns the underlying amqplib channel, connecting first if not already open.
|
|
69
|
+
* This is intended for internal use.
|
|
70
|
+
*/
|
|
71
|
+
native(): Promise<amqp.Channel | amqp.ConfirmChannel>;
|
|
72
|
+
/**
|
|
73
|
+
* Publish message directly using amqplib publish function.
|
|
74
|
+
* Handles backpressure (drain) and confirm-channel retries automatically.
|
|
75
|
+
* This is intended for internal use.
|
|
76
|
+
* Use `createProducer*` functions instead.
|
|
77
|
+
*
|
|
78
|
+
* @param exchange - Exchange name to publish to.
|
|
79
|
+
* @param routingKey - Routing key for the message.
|
|
80
|
+
* @param content - Serialized message body.
|
|
81
|
+
* @param options - Publish options including drain timeout and retry strategy.
|
|
82
|
+
* @returns `true` if the broker confirmed receipt (confirm channel), `false` if fire-and-forget (non-confirm channel).
|
|
83
|
+
*/
|
|
84
|
+
publish(exchange: string, routingKey: string, content: Buffer, options: ChannelPublishOptions): Promise<boolean>;
|
|
85
|
+
/**
|
|
86
|
+
* Create a producer that publishes directly to a queue using this channel.
|
|
87
|
+
* Each producer should have its own dedicated channel; this method uses the current
|
|
88
|
+
* channel. Consider using `connection.createProducerForQueue` or pass a channel
|
|
89
|
+
* in `options` param.
|
|
90
|
+
*
|
|
91
|
+
* @param queue - Target queue.
|
|
92
|
+
* @param options - Optional producer options (serialization, routing key, hooks, …).
|
|
93
|
+
*/
|
|
94
|
+
createProducerForQueue<T>(queue: Queue, options?: ProducerOptions<T>): Promise<Producer<T>>;
|
|
95
|
+
/**
|
|
96
|
+
* Create a producer that publishes to an exchange using this channel.
|
|
97
|
+
* Each producer should have its own dedicated channel; this method uses the current
|
|
98
|
+
* channel. Consider using `connection.createProducerForExchange` or pass a channel
|
|
99
|
+
* in `options` param.
|
|
100
|
+
*
|
|
101
|
+
* @param exchange - Target exchange.
|
|
102
|
+
* @param options - Optional producer options (serialization, routing key, hooks, …).
|
|
103
|
+
*/
|
|
104
|
+
createProducerForExchange<T>(exchange: Exchange, options?: ProducerOptions<T>): Promise<Producer<T>>;
|
|
105
|
+
/**
|
|
106
|
+
* Create a consumer that reads from a queue using this channel.
|
|
107
|
+
* Each consumer should have its own dedicated channel; this method uses the current
|
|
108
|
+
* channel. Consider using `connection.createConsumerForQueue` or pass a channel
|
|
109
|
+
* in `options` param.
|
|
110
|
+
*
|
|
111
|
+
* @param queue - Source queue.
|
|
112
|
+
* @param options - Optional consumer options (failure strategy, prefetch, …).
|
|
113
|
+
*/
|
|
114
|
+
createConsumerForQueue<T>(queue: Queue, options?: ConsumerOptions<T>): Promise<Consumer<T>>;
|
|
115
|
+
/**
|
|
116
|
+
* Create a consumer that reads from an exchange using this channel.
|
|
117
|
+
* Internally asserts an exclusive queue and binds it to the exchange.
|
|
118
|
+
* Each consumer should have its own dedicated channel; this method uses the current
|
|
119
|
+
* channel. Consider using `connection.createConsumerForExchange` or pass a channel
|
|
120
|
+
* in `options` param.
|
|
121
|
+
*
|
|
122
|
+
* @param exchange - Source exchange.
|
|
123
|
+
* @param options - Consumer options including the binding pattern.
|
|
124
|
+
* @param queueOptions - Options for the auto-created exclusive queue binding.
|
|
125
|
+
*/
|
|
126
|
+
createConsumerForExchange<T>(exchange: Exchange, options: ExchangeConsumerOptions<T>, queueOptions?: ExchangeConsumerQueueOptions): Promise<Consumer<T>>;
|
|
127
|
+
/**
|
|
128
|
+
* Create a batch consumer that reads from a queue using this channel.
|
|
129
|
+
* Each consumer should have its own dedicated channel; this method uses the current
|
|
130
|
+
* channel. Consider using `connection.createBatchConsumerForQueue` or pass a channel
|
|
131
|
+
* in `options` param.
|
|
132
|
+
*
|
|
133
|
+
* @param queue - Source queue.
|
|
134
|
+
* @param options - Optional batch consumer options (batch size, failure strategy, prefetch, …).
|
|
135
|
+
*/
|
|
136
|
+
createBatchConsumerForQueue<T>(queue: Queue, options?: BatchConsumerOptions<T>): Promise<BatchConsumer<T>>;
|
|
137
|
+
/**
|
|
138
|
+
* Create a batch consumer that reads from an exchange using this channel.
|
|
139
|
+
* Internally asserts an exclusive queue and binds it to the exchange.
|
|
140
|
+
* Each consumer should have its own dedicated channel; this method uses the current
|
|
141
|
+
* channel. Consider using `connection.createBatchConsumerForExchange` or pass a channel
|
|
142
|
+
* in `options` param.
|
|
143
|
+
*
|
|
144
|
+
* @param exchange - Source exchange.
|
|
145
|
+
* @param options - Batch consumer options including the binding pattern.
|
|
146
|
+
* @param queueOptions - Options for the auto-created exclusive queue binding.
|
|
147
|
+
*/
|
|
148
|
+
createBatchConsumerForExchange<T>(exchange: Exchange, options: ExchangeBatchConsumerOptions<T>, queueOptions?: ExchangeConsumerQueueOptions): Promise<BatchConsumer<T>>;
|
|
149
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ChannelImplementation } from './channel-implementation';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as amqp from 'amqplib';
|
|
2
|
+
import { ProducerPublishOptions } from '../producer';
|
|
3
|
+
export type ChannelPublishOptions = ProducerPublishOptions & {
|
|
4
|
+
drainTimeout: number;
|
|
5
|
+
};
|
|
6
|
+
export type ChannelWrapper = ({
|
|
7
|
+
isConfirmed: true;
|
|
8
|
+
channel: Promise<amqp.ConfirmChannel> | null;
|
|
9
|
+
} | {
|
|
10
|
+
isConfirmed: false;
|
|
11
|
+
channel: Promise<amqp.Channel> | null;
|
|
12
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { EventEmitter } from 'events';
|
|
2
|
+
import * as amqp from 'amqplib';
|
|
3
|
+
import { RetryStrategy } from '../retry';
|
|
4
|
+
import { Channel } from '../channel';
|
|
5
|
+
import { Exchange, ExchangeConsumerQueueOptions, ExchangeConsumerOptions, ExchangeBatchConsumerOptions } from '../exchange';
|
|
6
|
+
import { Consumer, ConsumerOptions, BatchConsumer, BatchConsumerOptions } from '../consumer';
|
|
7
|
+
import { Queue } from '../queue';
|
|
8
|
+
import { ProducerOptions, Producer } from '../producer';
|
|
9
|
+
import { Connection, ConnectionEventMap, ConnectionState } from './connection';
|
|
10
|
+
export declare class ConnectionImplementation extends EventEmitter<ConnectionEventMap> implements Connection {
|
|
11
|
+
private readonly options;
|
|
12
|
+
private readonly socketOptions?;
|
|
13
|
+
private readonly retryStrategy;
|
|
14
|
+
private connection;
|
|
15
|
+
private closingHandler;
|
|
16
|
+
private connectionState;
|
|
17
|
+
constructor(options: amqp.Options.Connect, retryStrategy?: RetryStrategy, socketOptions?: unknown | undefined);
|
|
18
|
+
connect(): Promise<this>;
|
|
19
|
+
close(timeout?: number): Promise<void>;
|
|
20
|
+
state(): ConnectionState;
|
|
21
|
+
native(): Promise<amqp.ChannelModel>;
|
|
22
|
+
createChannel(isConfirmed?: boolean): Channel;
|
|
23
|
+
createConsumerForExchange<T>(exchange: Exchange, options: ExchangeConsumerOptions<T>, queueOptions?: ExchangeConsumerQueueOptions): Promise<Consumer<T>>;
|
|
24
|
+
createConsumerForQueue<T>(queue: Queue, options?: ConsumerOptions<T>): Promise<Consumer<T>>;
|
|
25
|
+
createBatchConsumerForQueue<T>(queue: Queue, options?: BatchConsumerOptions<T>): Promise<BatchConsumer<T>>;
|
|
26
|
+
createBatchConsumerForExchange<T>(exchange: Exchange, options: ExchangeBatchConsumerOptions<T>, queueOptions?: ExchangeConsumerQueueOptions): Promise<BatchConsumer<T>>;
|
|
27
|
+
createProducerForExchange<T>(exchange: Exchange, options?: ProducerOptions<T>, isConfirmed?: boolean): Promise<Producer<T>>;
|
|
28
|
+
createProducerForQueue<T>(queue: Queue, options?: ProducerOptions<T>, isConfirmed?: boolean): Promise<Producer<T>>;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Creates a {@link ConnectionImplementation} and establishes the connection in one step.
|
|
32
|
+
* Equivalent to `new ConnectionImplementation(...args).connect()`.
|
|
33
|
+
* @param args - Same arguments as the {@link ConnectionImplementation} constructor.
|
|
34
|
+
*/
|
|
35
|
+
export declare function connect(...args: ConstructorParameters<typeof ConnectionImplementation>): Promise<Connection>;
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { debuglog } from 'util';
|
|
11
|
+
import { EventEmitter } from 'events';
|
|
12
|
+
import * as amqp from 'amqplib';
|
|
13
|
+
import { DEFAULT_RETRY_STRATEGY, normalizeRetryStrategy, retryLoop } from '../retry';
|
|
14
|
+
import { ChannelImplementation } from '../channel';
|
|
15
|
+
import { TooManyRetriesError } from '../errors';
|
|
16
|
+
import { errToMessage, LIB_NAME, maskAmqpUrl, sleepPromise } from '../utils';
|
|
17
|
+
import { ConnectionState } from './connection';
|
|
18
|
+
const debug = debuglog(`${LIB_NAME}:connection`);
|
|
19
|
+
export class ConnectionImplementation extends EventEmitter {
|
|
20
|
+
constructor(options, retryStrategy = {}, socketOptions) {
|
|
21
|
+
super();
|
|
22
|
+
this.options = options;
|
|
23
|
+
this.socketOptions = socketOptions;
|
|
24
|
+
this.connection = null;
|
|
25
|
+
this.closingHandler = null;
|
|
26
|
+
this.connectionState = ConnectionState.preconnect;
|
|
27
|
+
this.retryStrategy = normalizeRetryStrategy(Object.assign(Object.assign({}, DEFAULT_RETRY_STRATEGY), retryStrategy));
|
|
28
|
+
}
|
|
29
|
+
connect() {
|
|
30
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
+
if (this.connection) {
|
|
32
|
+
yield this.connection;
|
|
33
|
+
return this;
|
|
34
|
+
}
|
|
35
|
+
this.connection = (() => __awaiter(this, void 0, void 0, function* () {
|
|
36
|
+
this.connectionState = ConnectionState.connecting;
|
|
37
|
+
debug('connecting url=%s', maskAmqpUrl(this.options));
|
|
38
|
+
try {
|
|
39
|
+
const nativeConnection = yield retryLoop(this.retryStrategy, () => {
|
|
40
|
+
const terminationStates = [ConnectionState.closed, ConnectionState.closing];
|
|
41
|
+
if (terminationStates.includes(this.connectionState))
|
|
42
|
+
return null;
|
|
43
|
+
return amqp.connect(this.options, this.socketOptions);
|
|
44
|
+
}, error => {
|
|
45
|
+
this.emit('connectionError', error);
|
|
46
|
+
debug('retry-connection error=%s', errToMessage(error));
|
|
47
|
+
return true;
|
|
48
|
+
});
|
|
49
|
+
if (!nativeConnection)
|
|
50
|
+
return null;
|
|
51
|
+
this.connectionState = ConnectionState.connected;
|
|
52
|
+
debug('connected url=%s', maskAmqpUrl(this.options));
|
|
53
|
+
this.emit('connected', this);
|
|
54
|
+
nativeConnection.on('close', () => {
|
|
55
|
+
this.connection = null;
|
|
56
|
+
if ([ConnectionState.closed, ConnectionState.closing].includes(this.connectionState))
|
|
57
|
+
return;
|
|
58
|
+
debug('reconnecting url=%s', maskAmqpUrl(this.options));
|
|
59
|
+
this.emit('reconnecting');
|
|
60
|
+
this.connect().catch(() => { });
|
|
61
|
+
});
|
|
62
|
+
nativeConnection.on('error', err => {
|
|
63
|
+
debug('native-error error=%s', errToMessage(err));
|
|
64
|
+
this.emit('error', err);
|
|
65
|
+
});
|
|
66
|
+
return nativeConnection;
|
|
67
|
+
}
|
|
68
|
+
catch (err) {
|
|
69
|
+
this.connection = null;
|
|
70
|
+
this.connectionState = ConnectionState.closed;
|
|
71
|
+
if (err instanceof TooManyRetriesError) {
|
|
72
|
+
this.emit('connectionRetryExhausted');
|
|
73
|
+
debug('retry-exhausted last-error=%s', err.message);
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
debug('connecting-error error=%s', err === null || err === void 0 ? void 0 : err.message);
|
|
77
|
+
}
|
|
78
|
+
throw err;
|
|
79
|
+
}
|
|
80
|
+
}))();
|
|
81
|
+
yield this.connection;
|
|
82
|
+
return this;
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
close() {
|
|
86
|
+
return __awaiter(this, arguments, void 0, function* (timeout = 30000) {
|
|
87
|
+
if ([ConnectionState.closed, ConnectionState.preconnect].includes(this.connectionState))
|
|
88
|
+
return;
|
|
89
|
+
if (this.closingHandler)
|
|
90
|
+
return this.closingHandler;
|
|
91
|
+
this.closingHandler = (() => __awaiter(this, void 0, void 0, function* () {
|
|
92
|
+
var _a;
|
|
93
|
+
debug('closing url=%s', maskAmqpUrl(this.options));
|
|
94
|
+
this.connectionState = ConnectionState.closing;
|
|
95
|
+
const connection = yield ((_a = this.connection) === null || _a === void 0 ? void 0 : _a.catch(() => { }));
|
|
96
|
+
try {
|
|
97
|
+
const abort = new AbortController();
|
|
98
|
+
yield Promise.race([
|
|
99
|
+
Promise.resolve(connection === null || connection === void 0 ? void 0 : connection.close()).then(() => abort.abort()),
|
|
100
|
+
sleepPromise(timeout).then(() => {
|
|
101
|
+
if (!abort.signal.aborted)
|
|
102
|
+
throw new Error('Connection close timed out');
|
|
103
|
+
}),
|
|
104
|
+
]);
|
|
105
|
+
}
|
|
106
|
+
finally {
|
|
107
|
+
this.closingHandler = null;
|
|
108
|
+
this.connection = null;
|
|
109
|
+
this.connectionState = ConnectionState.closed;
|
|
110
|
+
debug('closed url=%s', maskAmqpUrl(this.options));
|
|
111
|
+
this.emit('close');
|
|
112
|
+
}
|
|
113
|
+
}))();
|
|
114
|
+
return this.closingHandler;
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
state() {
|
|
118
|
+
return this.connectionState;
|
|
119
|
+
}
|
|
120
|
+
native() {
|
|
121
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
122
|
+
const connection = yield this.connection;
|
|
123
|
+
if (!connection || this.connectionState !== ConnectionState.connected)
|
|
124
|
+
yield this.connect();
|
|
125
|
+
const establishedConnection = yield this.connection;
|
|
126
|
+
if (!establishedConnection)
|
|
127
|
+
throw new Error('Internal error: Connection is null after connect');
|
|
128
|
+
return establishedConnection;
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
createChannel(isConfirmed = false) {
|
|
132
|
+
return new ChannelImplementation(this, isConfirmed);
|
|
133
|
+
}
|
|
134
|
+
createConsumerForExchange(exchange, options, queueOptions) {
|
|
135
|
+
return this.createChannel().createConsumerForExchange(exchange, options, queueOptions);
|
|
136
|
+
}
|
|
137
|
+
createConsumerForQueue(queue, options) {
|
|
138
|
+
return this.createChannel().createConsumerForQueue(queue, options);
|
|
139
|
+
}
|
|
140
|
+
createBatchConsumerForQueue(queue, options) {
|
|
141
|
+
return this.createChannel().createBatchConsumerForQueue(queue, options);
|
|
142
|
+
}
|
|
143
|
+
createBatchConsumerForExchange(exchange, options, queueOptions) {
|
|
144
|
+
return this.createChannel().createBatchConsumerForExchange(exchange, options, queueOptions);
|
|
145
|
+
}
|
|
146
|
+
createProducerForExchange(exchange, options, isConfirmed) {
|
|
147
|
+
return this.createChannel(isConfirmed).createProducerForExchange(exchange, options);
|
|
148
|
+
}
|
|
149
|
+
createProducerForQueue(queue, options, isConfirmed) {
|
|
150
|
+
return this.createChannel(isConfirmed).createProducerForQueue(queue, options);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
export function connect(...args) {
|
|
154
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
155
|
+
return new ConnectionImplementation(...args).connect();
|
|
156
|
+
});
|
|
157
|
+
}
|