amqpx 0.0.0 → 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/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 +67 -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 +55 -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 +67 -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 +55 -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,21 @@
|
|
|
1
|
+
import { Channel } from '../channel';
|
|
2
|
+
import { Exchange } from '../exchange';
|
|
3
|
+
import { ConsumerOptions, Consumer, BatchConsumerOptions, BatchConsumer } from '../consumer';
|
|
4
|
+
import { ProducerOptions, ProducerImplementation } from '../producer';
|
|
5
|
+
import { Queue } from './queue';
|
|
6
|
+
import { BindingArgs, QueueOptions } from './types';
|
|
7
|
+
export declare class QueueImplementation implements Queue {
|
|
8
|
+
private readonly channel;
|
|
9
|
+
private readonly queueName;
|
|
10
|
+
private readonly options?;
|
|
11
|
+
private assertPromise;
|
|
12
|
+
constructor(channel: Channel, queueName: string, options?: QueueOptions);
|
|
13
|
+
assert(): Promise<this>;
|
|
14
|
+
name(): Promise<string>;
|
|
15
|
+
bindExchange(exchange: Exchange, pattern: string, args?: BindingArgs): Promise<this>;
|
|
16
|
+
createConsumer<T>(options?: ConsumerOptions<T>): Promise<Consumer<T>>;
|
|
17
|
+
createBatchConsumer<T>(options?: BatchConsumerOptions<T>): Promise<BatchConsumer<T>>;
|
|
18
|
+
createProducer<T>(options?: ProducerOptions<T> & {
|
|
19
|
+
isConfirmed?: boolean;
|
|
20
|
+
}): Promise<ProducerImplementation<T>>;
|
|
21
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.QueueImplementation = void 0;
|
|
13
|
+
const util_1 = require("util");
|
|
14
|
+
const consumer_1 = require("../consumer");
|
|
15
|
+
const producer_1 = require("../producer");
|
|
16
|
+
const index_1 = require("../index");
|
|
17
|
+
const utils_1 = require("../utils");
|
|
18
|
+
const types_1 = require("../types");
|
|
19
|
+
const debug = (0, util_1.debuglog)(`${utils_1.LIB_NAME}:queue`);
|
|
20
|
+
const DEFAULT_QUEUE_OPTIONS = {
|
|
21
|
+
assertionMode: types_1.AssertionMode.Assert,
|
|
22
|
+
};
|
|
23
|
+
class QueueImplementation {
|
|
24
|
+
constructor(channel, queueName, options) {
|
|
25
|
+
this.channel = channel;
|
|
26
|
+
this.queueName = queueName;
|
|
27
|
+
this.assertPromise = null;
|
|
28
|
+
this.options = (0, utils_1.deepMerge)({}, DEFAULT_QUEUE_OPTIONS, options !== null && options !== void 0 ? options : {});
|
|
29
|
+
this.channel.on('close', () => {
|
|
30
|
+
debug('native-close');
|
|
31
|
+
this.assertPromise = null;
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
assert() {
|
|
35
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
36
|
+
if (this.assertPromise) {
|
|
37
|
+
yield this.assertPromise;
|
|
38
|
+
return this;
|
|
39
|
+
}
|
|
40
|
+
this.assertPromise = (() => __awaiter(this, void 0, void 0, function* () {
|
|
41
|
+
var _a, _b, _c;
|
|
42
|
+
debug('assert name=%s mode=%s', this.queueName, (_a = this.options) === null || _a === void 0 ? void 0 : _a.assertionMode);
|
|
43
|
+
const channel = yield this.channel.native();
|
|
44
|
+
switch ((_b = this.options) === null || _b === void 0 ? void 0 : _b.assertionMode) {
|
|
45
|
+
case types_1.AssertionMode.Check:
|
|
46
|
+
yield channel.checkQueue(this.queueName);
|
|
47
|
+
debug('native-check-done name=%s', this.queueName);
|
|
48
|
+
break;
|
|
49
|
+
case types_1.AssertionMode.Assert:
|
|
50
|
+
yield channel.assertQueue(this.queueName, this.options);
|
|
51
|
+
debug('native-assert-done name=%s', this.queueName);
|
|
52
|
+
break;
|
|
53
|
+
case types_1.AssertionMode.Passive:
|
|
54
|
+
debug('no-assert name=%s mode=%s', this.queueName, this.options.assertionMode);
|
|
55
|
+
break;
|
|
56
|
+
default:
|
|
57
|
+
throw new Error(`Unknown assertion mode: ${(_c = this.options) === null || _c === void 0 ? void 0 : _c.assertionMode}`);
|
|
58
|
+
}
|
|
59
|
+
}))();
|
|
60
|
+
yield this.assertPromise;
|
|
61
|
+
debug('assert-complete name=%s', this.queueName);
|
|
62
|
+
return this;
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
name() {
|
|
66
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
67
|
+
return this.assert().then(self => self.queueName);
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
bindExchange(exchange, pattern, args) {
|
|
71
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
72
|
+
debug('bind-exchange queue=%s pattern=%s', this.queueName, pattern);
|
|
73
|
+
yield exchange.bindQueue(this, pattern, args);
|
|
74
|
+
return this;
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
createConsumer(options = {}) {
|
|
78
|
+
var _a;
|
|
79
|
+
return Promise.resolve(new consumer_1.ConsumerImplementation((_a = options.channel) !== null && _a !== void 0 ? _a : this.channel.connection.createChannel(), this, options));
|
|
80
|
+
}
|
|
81
|
+
createBatchConsumer(options = {}) {
|
|
82
|
+
var _a;
|
|
83
|
+
return Promise.resolve(new consumer_1.BatchConsumerImplementation((_a = options.channel) !== null && _a !== void 0 ? _a : this.channel.connection.createChannel(), this, options));
|
|
84
|
+
}
|
|
85
|
+
createProducer(options = {}) {
|
|
86
|
+
var _a;
|
|
87
|
+
const exchange = index_1.predefined.defaultExchange(this.channel);
|
|
88
|
+
return Promise.resolve(new producer_1.ProducerImplementation((_a = options.channel) !== null && _a !== void 0 ? _a : this.channel.connection.createChannel(options.isConfirmed), exchange, Object.assign(Object.assign({}, options), { routingKey: () => this.name() })));
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
exports.QueueImplementation = QueueImplementation;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { Exchange } from '../exchange';
|
|
2
|
+
import { ConsumerOptions, Consumer, BatchConsumerOptions, BatchConsumer } from '../consumer';
|
|
3
|
+
import { ProducerOptions, Producer } from '../producer';
|
|
4
|
+
import { BindingArgs } from './types';
|
|
5
|
+
export interface Queue {
|
|
6
|
+
/**
|
|
7
|
+
* Verify the queue against the broker, according to the configured `assertionMode`.
|
|
8
|
+
*
|
|
9
|
+
* - `Assert` (default) — declare the queue; creates it if absent, throws on config mismatch.
|
|
10
|
+
* - `Check` — verify the queue exists without creating it; throws if absent.
|
|
11
|
+
* - `Passive` — no-op; no network call is made.
|
|
12
|
+
*
|
|
13
|
+
* Subsequent calls return immediately once the first call completes successfully.
|
|
14
|
+
* Returns `this` to allow chaining.
|
|
15
|
+
*/
|
|
16
|
+
assert(): Promise<Queue>;
|
|
17
|
+
/**
|
|
18
|
+
* Returns the name of the queue.
|
|
19
|
+
* Asserts the queue first if it has not been asserted yet.
|
|
20
|
+
*/
|
|
21
|
+
name(): Promise<string>;
|
|
22
|
+
/**
|
|
23
|
+
* Bind this queue to an exchange.
|
|
24
|
+
* Asserts the queue first if it has not been asserted yet.
|
|
25
|
+
* @param exchange - Exchange to bind this queue to.
|
|
26
|
+
* @param pattern - Routing key pattern under which to bind.
|
|
27
|
+
* @param args - Optional AMQP headers or x-arguments for the binding.
|
|
28
|
+
*/
|
|
29
|
+
bindExchange(exchange: Exchange, pattern: string, args?: BindingArgs): Promise<Queue>;
|
|
30
|
+
/**
|
|
31
|
+
* Create consumer for current queue.
|
|
32
|
+
* By default, creates a new dedicated channel for the consumer.
|
|
33
|
+
* Pass a channel in `options` to use a specific one instead.
|
|
34
|
+
*/
|
|
35
|
+
createConsumer<T>(options?: ConsumerOptions<T>): Promise<Consumer<T>>;
|
|
36
|
+
/**
|
|
37
|
+
* Create batch consumer for current queue.
|
|
38
|
+
* By default, creates a new dedicated channel for the consumer.
|
|
39
|
+
* Pass a channel in `options` to use a specific one instead.
|
|
40
|
+
*/
|
|
41
|
+
createBatchConsumer<T>(options?: BatchConsumerOptions<T>): Promise<BatchConsumer<T>>;
|
|
42
|
+
/**
|
|
43
|
+
* Create producer for current queue.
|
|
44
|
+
* Publishes via the default RabbitMQ exchange, routing messages directly to this queue by name.
|
|
45
|
+
* By default, creates a new dedicated channel for the producer.
|
|
46
|
+
* Pass a channel in `options` to use a specific one instead.
|
|
47
|
+
*
|
|
48
|
+
* @param options - Optional producer options (serialization, routing key, hooks, …).
|
|
49
|
+
* Set `options.isConfirmed` to `true` to open the dedicated channel in confirm mode.
|
|
50
|
+
* Has no effect when `options.channel` is supplied.
|
|
51
|
+
*/
|
|
52
|
+
createProducer<T>(options?: ProducerOptions<T> & {
|
|
53
|
+
isConfirmed?: boolean;
|
|
54
|
+
}): Promise<Producer<T>>;
|
|
55
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import * as amqp from 'amqplib';
|
|
2
|
+
import { AssertionMode } from '../types';
|
|
3
|
+
import { Exchange } from '../exchange';
|
|
4
|
+
export type BindingArgs = Record<string, string | number | boolean>;
|
|
5
|
+
/**
|
|
6
|
+
* Options for asserting a queue on the broker.
|
|
7
|
+
* Extends the amqplib `AssertQueue` options with an additional `assertionMode` field.
|
|
8
|
+
*/
|
|
9
|
+
export type QueueOptions = amqp.Options.AssertQueue & {
|
|
10
|
+
/**
|
|
11
|
+
* Controls how the queue is verified against the broker when `assert()` is called.
|
|
12
|
+
* Defaults to `AssertionMode.Assert`.
|
|
13
|
+
*
|
|
14
|
+
* @see AssertionMode
|
|
15
|
+
*/
|
|
16
|
+
assertionMode?: AssertionMode;
|
|
17
|
+
};
|
|
18
|
+
type ExchangeName = string;
|
|
19
|
+
type Pattern = string;
|
|
20
|
+
export type Bindings = Record<ExchangeName, Record<Pattern, {
|
|
21
|
+
exchange: Exchange;
|
|
22
|
+
pattern: Pattern;
|
|
23
|
+
args?: BindingArgs;
|
|
24
|
+
}>>;
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default retry strategy used throughout the library when the user does not provide their own.
|
|
3
|
+
*
|
|
4
|
+
* Retries up to 10 times with exponential backoff starting at 100ms.
|
|
5
|
+
*/
|
|
6
|
+
export declare const DEFAULT_RETRY_STRATEGY: {
|
|
7
|
+
readonly maxRetries: 10;
|
|
8
|
+
readonly reconnectionTimeoutMs: (step: number) => number;
|
|
9
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEFAULT_RETRY_STRATEGY = void 0;
|
|
4
|
+
const time_strategies_1 = require("./time-strategies");
|
|
5
|
+
exports.DEFAULT_RETRY_STRATEGY = {
|
|
6
|
+
maxRetries: 10,
|
|
7
|
+
reconnectionTimeoutMs: (0, time_strategies_1.exponentialBackoff)(100),
|
|
8
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
36
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.retryLoop = exports.normalizeRetryStrategy = exports.retryStrategies = void 0;
|
|
40
|
+
exports.retryStrategies = __importStar(require("./time-strategies"));
|
|
41
|
+
var retry_strategy_1 = require("./retry-strategy");
|
|
42
|
+
Object.defineProperty(exports, "normalizeRetryStrategy", { enumerable: true, get: function () { return retry_strategy_1.normalizeRetryStrategy; } });
|
|
43
|
+
__exportStar(require("./default-retry-strategy"), exports);
|
|
44
|
+
var retry_implementation_1 = require("./retry-implementation");
|
|
45
|
+
Object.defineProperty(exports, "retryLoop", { enumerable: true, get: function () { return retry_implementation_1.retryLoop; } });
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { MaybePromise } from '../types';
|
|
2
|
+
import { RetryStrategy } from './retry-strategy';
|
|
3
|
+
/**
|
|
4
|
+
* Retries callback until it succeeds or reaches max retries.
|
|
5
|
+
*
|
|
6
|
+
* You can decide whether the retry (up to max attempts) should be done based on the error thrown by the callback.
|
|
7
|
+
*
|
|
8
|
+
* @param strategy Retry strategy to use. Missing properties will be taken from the default retry strategy,
|
|
9
|
+
* that by default retries 10 times with exponential delay. See {@link DEFAULT_RETRY_STRATEGY} for default values.
|
|
10
|
+
* @param callback Callback to call in the loop. If the callback throws an error, it will be caught and the loop will retry.
|
|
11
|
+
* If the callback returns a promise, it will be awaited and the loop will retry if the promise is rejected.
|
|
12
|
+
* @param shouldRetry Function that decides whether the retry should be performed based on the error thrown by the callback.
|
|
13
|
+
* If it returns true, the callback will be retried. If it returns false, the error will be thrown and the loop will end.
|
|
14
|
+
* @throws TooManyRetriesError if callback fails after max retries as specified by the retry strategy.
|
|
15
|
+
* @throws Error if callback throws an error for which `shouldRetry` returns false.
|
|
16
|
+
* @returns Result of the callback.
|
|
17
|
+
*/
|
|
18
|
+
export declare const retryLoop: <T>(strategy: RetryStrategy, callback: () => MaybePromise<T>, shouldRetry?: (error: unknown) => boolean) => Promise<T>;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.retryLoop = void 0;
|
|
13
|
+
const util_1 = require("util");
|
|
14
|
+
const utils_1 = require("../utils");
|
|
15
|
+
const errors_1 = require("../errors");
|
|
16
|
+
const retry_strategy_1 = require("./retry-strategy");
|
|
17
|
+
const debug = (0, util_1.debuglog)(`${utils_1.LIB_NAME}:retry`);
|
|
18
|
+
const retryLoop = (strategy_1, callback_1, ...args_1) => __awaiter(void 0, [strategy_1, callback_1, ...args_1], void 0, function* (strategy, callback, shouldRetry = () => true) {
|
|
19
|
+
const normalizedStrategy = (0, retry_strategy_1.normalizeRetryStrategy)(strategy);
|
|
20
|
+
let attempt = 0;
|
|
21
|
+
let lastErr = null;
|
|
22
|
+
while (attempt <= normalizedStrategy.maxRetries) {
|
|
23
|
+
attempt++;
|
|
24
|
+
debug('attempt current=%d total=%d', attempt, normalizedStrategy.maxRetries);
|
|
25
|
+
try {
|
|
26
|
+
return yield callback();
|
|
27
|
+
}
|
|
28
|
+
catch (err) {
|
|
29
|
+
lastErr = err;
|
|
30
|
+
if (shouldRetry(err)) {
|
|
31
|
+
const delay = normalizedStrategy.reconnectionTimeoutMs(attempt);
|
|
32
|
+
debug('attempt-failed retrying-in=%dms error=%s', delay, (0, utils_1.errToMessage)(err));
|
|
33
|
+
yield (0, utils_1.sleepPromise)(delay);
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
debug('non-retryable-error attempt=%d error=%s', attempt, (0, utils_1.errToMessage)(err));
|
|
37
|
+
throw err;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
debug('max-retries-exhausted attempts=%d error=%s', normalizedStrategy.maxRetries, (0, utils_1.errToMessage)(lastErr));
|
|
42
|
+
throw new errors_1.TooManyRetriesError(`Too many retries`, lastErr);
|
|
43
|
+
});
|
|
44
|
+
exports.retryLoop = retryLoop;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { TimeStrategy } from './time-strategies';
|
|
2
|
+
/**
|
|
3
|
+
* Retry strategy that controls the delay between attempts and the maximum number of retries.
|
|
4
|
+
*
|
|
5
|
+
* Delays may be fixed or dynamic, using the time strategies accessible from {@link retryStrategies}.
|
|
6
|
+
*/
|
|
7
|
+
export interface RetryStrategy {
|
|
8
|
+
/**
|
|
9
|
+
* Delay before the next retry attempt, in milliseconds.
|
|
10
|
+
* Can be a fixed number or a {@link TimeStrategy} function from {@link retryStrategies} for dynamic backoff.
|
|
11
|
+
*/
|
|
12
|
+
reconnectionTimeoutMs?: number | TimeStrategy;
|
|
13
|
+
/**
|
|
14
|
+
* Maximum number of retry attempts.
|
|
15
|
+
* After this many failed attempts, a `TooManyRetriesError` is thrown.
|
|
16
|
+
*/
|
|
17
|
+
maxRetries?: number;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Normalizes a retry strategy so that all properties are defined.
|
|
21
|
+
* Missing properties are filled in from {@link DEFAULT_RETRY_STRATEGY}.
|
|
22
|
+
* Always converts `reconnectionTimeoutMs` to a {@link TimeStrategy} function.
|
|
23
|
+
*
|
|
24
|
+
* @param retryStrategy - Retry strategy to normalize.
|
|
25
|
+
*/
|
|
26
|
+
export declare const normalizeRetryStrategy: (retryStrategy: RetryStrategy) => Required<Omit<RetryStrategy, "reconnectionTimeoutMs">> & {
|
|
27
|
+
reconnectionTimeoutMs: TimeStrategy;
|
|
28
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.normalizeRetryStrategy = void 0;
|
|
4
|
+
const time_strategies_1 = require("./time-strategies");
|
|
5
|
+
const default_retry_strategy_1 = require("./default-retry-strategy");
|
|
6
|
+
const normalizeRetryStrategy = (retryStrategy) => {
|
|
7
|
+
const mergedWithDefault = Object.assign(Object.assign({}, default_retry_strategy_1.DEFAULT_RETRY_STRATEGY), retryStrategy);
|
|
8
|
+
return typeof mergedWithDefault.reconnectionTimeoutMs === 'number' ? Object.assign(Object.assign({}, mergedWithDefault), { reconnectionTimeoutMs: (0, time_strategies_1.linearBackoff)(mergedWithDefault.reconnectionTimeoutMs) }) : Object.assign(Object.assign({}, mergedWithDefault), { reconnectionTimeoutMs: mergedWithDefault.reconnectionTimeoutMs });
|
|
9
|
+
};
|
|
10
|
+
exports.normalizeRetryStrategy = normalizeRetryStrategy;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Function specification for time strategy. It takes step number and returns delay for this step.
|
|
3
|
+
* @param step Step number. Starts from 1.
|
|
4
|
+
*/
|
|
5
|
+
export type TimeStrategy = (step: number) => number;
|
|
6
|
+
/**
|
|
7
|
+
* Returns a constant `delay` on every step, regardless of the step number.
|
|
8
|
+
* @param delay Delay in ms.
|
|
9
|
+
* @param jitter Jitter factor in [0, 1]. Randomizes the delay within ±`jitter * delay`. Use `0` to disable jitter.
|
|
10
|
+
*/
|
|
11
|
+
export declare const linearBackoff: (delay: number, jitter?: number) => (_step: number) => number;
|
|
12
|
+
/**
|
|
13
|
+
* Increases the delay each step using the formula `multiplier * base^(step-1)`.
|
|
14
|
+
* For `base=2` and `multiplier=100` results in the series: 100, 200, 400, 800, ...
|
|
15
|
+
* @param multiplier Multiplier of the function, specifying the delay at the first step. Default is 100.
|
|
16
|
+
* @param base Base of the exponential function. Default is 2, resulting in doubling the time each step.
|
|
17
|
+
* @param jitter Jitter factor in [0, 1]. Randomizes the delay within ±`jitter * delay`. Use `0` to disable jitter.
|
|
18
|
+
*/
|
|
19
|
+
export declare const exponentialBackoff: (multiplier: number, base?: number, jitter?: number) => (step: number) => number;
|
|
20
|
+
/**
|
|
21
|
+
* Increases the delay each step using the formula `multiplier * base^(step-1)`, capped at `maxDelay`.
|
|
22
|
+
* Behaves identically to {@link exponentialBackoff} but clamps the result to `maxDelay` before applying jitter.
|
|
23
|
+
* For `base=2`, `multiplier=100`, and `maxDelay=500` results in the series: 100, 200, 400, 500, 500, ...
|
|
24
|
+
* @param multiplier Multiplier of the function, specifying the delay at the first step.
|
|
25
|
+
* @param maxDelay Maximum delay in ms. The raw exponential value is clamped to this before jitter is applied.
|
|
26
|
+
* @param base Base of the exponential function. Default is 2, resulting in doubling the time each step.
|
|
27
|
+
* @param jitter Jitter factor in [0, 1]. Randomizes the delay within ±`jitter * delay`. Use `0` to disable jitter.
|
|
28
|
+
*/
|
|
29
|
+
export declare const cappedExponentialBackoff: (multiplier: number, maxDelay: number, base?: number, jitter?: number) => (step: number) => number;
|
|
30
|
+
/**
|
|
31
|
+
* Increases the delay each step using the formula `multiplier * step^exponent`.
|
|
32
|
+
* For `exponent=2` (quadratic) and `multiplier=100` results in the series: 100, 400, 900, 1600, ...
|
|
33
|
+
* @param multiplier Multiplier of the function, specifying the delay at the first step.
|
|
34
|
+
* @param exponent Exponent of the polynomial. Default is 2 (quadratic).
|
|
35
|
+
* @param jitter Jitter factor in [0, 1]. Randomizes the delay within ±`jitter * delay`. Use `0` to disable jitter.
|
|
36
|
+
*/
|
|
37
|
+
export declare const polynomialBackoff: (multiplier: number, exponent?: number, jitter?: number) => (step: number) => number;
|
|
38
|
+
/**
|
|
39
|
+
* Increases the delay each step following the Fibonacci sequence scaled by `multiplier`.
|
|
40
|
+
* Results in the series: `multiplier * 1, multiplier * 1, multiplier * 2, multiplier * 3, multiplier * 5, ...`
|
|
41
|
+
* Grows slower than exponential, useful when exponential backoff is too aggressive.
|
|
42
|
+
* @param multiplier Scale factor applied to each Fibonacci number, specifying the delay at step 1.
|
|
43
|
+
* @param jitter Jitter factor in [0, 1]. Randomizes the delay within ±`jitter * delay`. Use `0` to disable jitter.
|
|
44
|
+
*/
|
|
45
|
+
export declare const fibonacciBackoff: (multiplier: number, jitter?: number) => (step: number) => number;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fibonacciBackoff = exports.polynomialBackoff = exports.cappedExponentialBackoff = exports.exponentialBackoff = exports.linearBackoff = void 0;
|
|
4
|
+
const addJitter = (delay, jitterFactor) => {
|
|
5
|
+
const clampedFactor = Math.min(1, Math.max(0, jitterFactor));
|
|
6
|
+
return Math.floor(clampedFactor > 0 ? delay + (Math.random() * 2 - 1) * (delay * clampedFactor) : delay);
|
|
7
|
+
};
|
|
8
|
+
const linearBackoff = (delay, jitter = 0.25) => (_step) => addJitter(delay, jitter);
|
|
9
|
+
exports.linearBackoff = linearBackoff;
|
|
10
|
+
const exponentialBackoff = (multiplier, base = 2, jitter = 0.25) => (step) => {
|
|
11
|
+
const delay = multiplier * Math.pow(base, step - 1);
|
|
12
|
+
return addJitter(delay, jitter);
|
|
13
|
+
};
|
|
14
|
+
exports.exponentialBackoff = exponentialBackoff;
|
|
15
|
+
const cappedExponentialBackoff = (multiplier, maxDelay, base = 2, jitter = 0.25) => (step) => {
|
|
16
|
+
const delay = Math.min(maxDelay, multiplier * Math.pow(base, step - 1));
|
|
17
|
+
return addJitter(delay, jitter);
|
|
18
|
+
};
|
|
19
|
+
exports.cappedExponentialBackoff = cappedExponentialBackoff;
|
|
20
|
+
const polynomialBackoff = (multiplier, exponent = 2, jitter = 0.25) => (step) => {
|
|
21
|
+
const delay = multiplier * Math.pow(step, exponent);
|
|
22
|
+
return addJitter(delay, jitter);
|
|
23
|
+
};
|
|
24
|
+
exports.polynomialBackoff = polynomialBackoff;
|
|
25
|
+
const fibonacciBackoff = (multiplier, jitter = 0.25) => (step) => {
|
|
26
|
+
let a = 1;
|
|
27
|
+
let b = 1;
|
|
28
|
+
for (let i = 2; i < step; i++)
|
|
29
|
+
[a, b] = [b, a + b];
|
|
30
|
+
return addJitter(multiplier * (step === 1 ? 1 : b), jitter);
|
|
31
|
+
};
|
|
32
|
+
exports.fibonacciBackoff = fibonacciBackoff;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A value that is either already resolved (`T`) or wrapped in a `Promise<T>`.
|
|
3
|
+
* Used throughout the library to accept both synchronous and asynchronous callbacks.
|
|
4
|
+
*/
|
|
5
|
+
export type MaybePromise<T> = Promise<T> | T;
|
|
6
|
+
/**
|
|
7
|
+
* Controls how an entity is verified against the broker when `assert()` is called.
|
|
8
|
+
*
|
|
9
|
+
* - `Assert` (default) — declare the entity, creating it if absent; fail on config mismatch.
|
|
10
|
+
* - `Check` — verify the entity exists without creating it; fail if absent.
|
|
11
|
+
* - `Passive` — skip all broker interaction; no network call is made.
|
|
12
|
+
*/
|
|
13
|
+
export declare enum AssertionMode {
|
|
14
|
+
/**
|
|
15
|
+
* Assert the entity against the broker.
|
|
16
|
+
* Creates it if absent; throws if it exists with incompatible options.
|
|
17
|
+
* This is the default mode.
|
|
18
|
+
*/
|
|
19
|
+
Assert = "Assert",
|
|
20
|
+
/**
|
|
21
|
+
* Only check that the entity exists on the broker.
|
|
22
|
+
* Does not create it; throws if absent.
|
|
23
|
+
*/
|
|
24
|
+
Check = "Check",
|
|
25
|
+
/**
|
|
26
|
+
* Skip all broker-side verification.
|
|
27
|
+
* No network call is made when `assert()` is invoked.
|
|
28
|
+
*/
|
|
29
|
+
Passive = "Passive"
|
|
30
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AssertionMode = void 0;
|
|
4
|
+
var AssertionMode;
|
|
5
|
+
(function (AssertionMode) {
|
|
6
|
+
AssertionMode["Assert"] = "Assert";
|
|
7
|
+
AssertionMode["Check"] = "Check";
|
|
8
|
+
AssertionMode["Passive"] = "Passive";
|
|
9
|
+
})(AssertionMode || (exports.AssertionMode = AssertionMode = {}));
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare const LIB_NAME = "amqpx";
|
|
2
|
+
export declare const sleepPromise: (ms: number) => Promise<void>;
|
|
3
|
+
export declare const deepMerge: <T extends object>(target: T, ...sources: Array<Partial<T>>) => T;
|
|
4
|
+
export declare const last: <T>(arr: T[]) => T | undefined;
|
|
5
|
+
export declare const zip: <T, U>(arr1: T[], arr2: U[]) => [T, U][];
|
|
6
|
+
export declare function swallowError<T>(callback: () => Promise<T>): Promise<T | null>;
|
|
7
|
+
export declare function swallowError<T>(callback: () => T): T | null;
|
|
8
|
+
export declare function swallowError<T>(promise: Promise<T>): Promise<T | null>;
|
|
9
|
+
export declare function maskAmqpUrl(options: import('amqplib').Options.Connect | string): string;
|
|
10
|
+
export declare const errToMessage: (err: unknown) => string;
|
|
11
|
+
export declare const externallyResolvedPromise: <T = void>() => readonly [Promise<T>, (v: T) => void];
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.externallyResolvedPromise = exports.errToMessage = exports.zip = exports.last = exports.deepMerge = exports.sleepPromise = exports.LIB_NAME = void 0;
|
|
4
|
+
exports.swallowError = swallowError;
|
|
5
|
+
exports.maskAmqpUrl = maskAmqpUrl;
|
|
6
|
+
exports.LIB_NAME = 'amqpx';
|
|
7
|
+
const sleepPromise = (ms) => new Promise(resolve => setTimeout(resolve, ms));
|
|
8
|
+
exports.sleepPromise = sleepPromise;
|
|
9
|
+
const isObject = (item) => (!!item && typeof item === 'object' && !Array.isArray(item));
|
|
10
|
+
const deepMerge = (target, ...sources) => {
|
|
11
|
+
if (sources.length === 0)
|
|
12
|
+
return target;
|
|
13
|
+
const [source, ...restSources] = sources;
|
|
14
|
+
if (isObject(target) && isObject(source)) {
|
|
15
|
+
for (const key in source) {
|
|
16
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
17
|
+
const typedKey = key;
|
|
18
|
+
const sourceValue = source[typedKey];
|
|
19
|
+
const targetValue = target[typedKey];
|
|
20
|
+
if (isObject(sourceValue) && isObject(targetValue)) {
|
|
21
|
+
target[typedKey] = (0, exports.deepMerge)(targetValue, sourceValue);
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
target[typedKey] = sourceValue;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return (0, exports.deepMerge)(target, ...restSources);
|
|
30
|
+
};
|
|
31
|
+
exports.deepMerge = deepMerge;
|
|
32
|
+
const last = (arr) => {
|
|
33
|
+
const index = arr.length - 1;
|
|
34
|
+
if (index < 0)
|
|
35
|
+
return undefined;
|
|
36
|
+
return arr[index];
|
|
37
|
+
};
|
|
38
|
+
exports.last = last;
|
|
39
|
+
const zip = (arr1, arr2) => {
|
|
40
|
+
const length = Math.min(arr1.length, arr2.length);
|
|
41
|
+
const result = [];
|
|
42
|
+
for (let i = 0; i < length; i++)
|
|
43
|
+
result.push([arr1[i], arr2[i]]);
|
|
44
|
+
return result;
|
|
45
|
+
};
|
|
46
|
+
exports.zip = zip;
|
|
47
|
+
function swallowError(callback) {
|
|
48
|
+
try {
|
|
49
|
+
const result = typeof callback === 'function' ? callback() : callback;
|
|
50
|
+
if (result instanceof Promise)
|
|
51
|
+
return result.catch(() => null);
|
|
52
|
+
return result;
|
|
53
|
+
}
|
|
54
|
+
catch (_a) {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
function maskAmqpUrl(options) {
|
|
59
|
+
var _a, _b, _c;
|
|
60
|
+
if (typeof options === 'string')
|
|
61
|
+
return options.replace(/:\/\/([^:@]+):([^@]+)@/, '://$1:***@');
|
|
62
|
+
const host = (_a = options.hostname) !== null && _a !== void 0 ? _a : 'localhost';
|
|
63
|
+
const port = (_b = options.port) !== null && _b !== void 0 ? _b : 5672;
|
|
64
|
+
const vhost = options.vhost ? `/${options.vhost}` : '';
|
|
65
|
+
const user = (_c = options.username) !== null && _c !== void 0 ? _c : 'guest';
|
|
66
|
+
return `amqp://${user}:***@${host}:${port}${vhost}`;
|
|
67
|
+
}
|
|
68
|
+
const errToMessage = (err) => {
|
|
69
|
+
if (err instanceof Error)
|
|
70
|
+
return err.message;
|
|
71
|
+
if (err !== null && typeof err === 'object' && 'message' in err)
|
|
72
|
+
return `${err.message}`;
|
|
73
|
+
return String(err);
|
|
74
|
+
};
|
|
75
|
+
exports.errToMessage = errToMessage;
|
|
76
|
+
const externallyResolvedPromise = () => {
|
|
77
|
+
let release;
|
|
78
|
+
const latch = new Promise(resolve => {
|
|
79
|
+
release = resolve;
|
|
80
|
+
});
|
|
81
|
+
return [latch, release];
|
|
82
|
+
};
|
|
83
|
+
exports.externallyResolvedPromise = externallyResolvedPromise;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { EventEmitter } from 'events';
|
|
2
|
+
import * as amqp from 'amqplib';
|
|
3
|
+
import { Replies } from 'amqplib';
|
|
4
|
+
import { Connection } from '../connection';
|
|
5
|
+
import { Exchange, ExchangeTypes, ExchangeConsumerQueueOptions, ExchangeConsumerOptions, ExchangeBatchConsumerOptions, ExchangeOptions } from '../exchange';
|
|
6
|
+
import { Queue, QueueOptions } from '../queue';
|
|
7
|
+
import { ProducerOptions, Producer } from '../producer';
|
|
8
|
+
import { Consumer, ConsumerOptions, BatchConsumer, BatchConsumerOptions } from '../consumer';
|
|
9
|
+
import { Channel, ChannelEventMap } from './channel';
|
|
10
|
+
import { ChannelPublishOptions } from './types';
|
|
11
|
+
export declare class ChannelImplementation extends EventEmitter<ChannelEventMap> implements Channel {
|
|
12
|
+
readonly connection: Connection;
|
|
13
|
+
private readonly wrapper;
|
|
14
|
+
private closeHandler;
|
|
15
|
+
private drainPromise;
|
|
16
|
+
constructor(connection: Connection, publishConfirm: boolean);
|
|
17
|
+
connect(): Promise<ChannelImplementation>;
|
|
18
|
+
close(timeout?: number): Promise<void>;
|
|
19
|
+
createExchange(name: string, type: ExchangeTypes, options?: ExchangeOptions): Promise<Exchange>;
|
|
20
|
+
createQueue(name: string, options?: QueueOptions): Promise<Queue>;
|
|
21
|
+
checkQueue(name: string): Promise<Replies.AssertQueue>;
|
|
22
|
+
native(): Promise<amqp.Channel | amqp.ConfirmChannel>;
|
|
23
|
+
publish(exchange: string, routingKey: string, content: Buffer, optionsArgs: ChannelPublishOptions): Promise<boolean>;
|
|
24
|
+
createProducerForQueue<T>(queue: Queue, options?: ProducerOptions<T>): Promise<Producer<T>>;
|
|
25
|
+
createProducerForExchange<T>(exchange: Exchange, options?: ProducerOptions<T>): Promise<Producer<T>>;
|
|
26
|
+
createConsumerForQueue<T>(queue: Queue, options?: ConsumerOptions<T>): Promise<Consumer<T>>;
|
|
27
|
+
createConsumerForExchange<T>(exchange: Exchange, options: ExchangeConsumerOptions<T>, queueOptions?: ExchangeConsumerQueueOptions): Promise<Consumer<T>>;
|
|
28
|
+
createBatchConsumerForQueue<T>(queue: Queue, options?: BatchConsumerOptions<T>): Promise<BatchConsumer<T>>;
|
|
29
|
+
createBatchConsumerForExchange<T>(exchange: Exchange, options: ExchangeBatchConsumerOptions<T>, queueOptions?: ExchangeConsumerQueueOptions): Promise<BatchConsumer<T>>;
|
|
30
|
+
}
|