amqpx 1.0.1 → 1.0.3
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 +3 -3
- package/dist/cjs/connection/connection-implementation.d.ts +1 -1
- package/dist/cjs/exchange/exchange-implementation.d.ts +1 -0
- package/dist/cjs/exchange/exchange-implementation.js +6 -29
- package/dist/cjs/exchange/exchange.d.ts +13 -12
- package/dist/cjs/exchange/types.d.ts +4 -13
- package/dist/cjs/exchange/types.js +0 -6
- package/dist/cjs/extensions/vitest/test-batch-consumer.d.ts +3 -2
- package/dist/cjs/extensions/vitest/test-channel.d.ts +17 -26
- package/dist/cjs/extensions/vitest/test-connection.d.ts +12 -11
- package/dist/cjs/extensions/vitest/test-consumer.d.ts +4 -3
- package/dist/cjs/extensions/vitest/test-exchange.d.ts +8 -7
- package/dist/cjs/extensions/vitest/test-producer.d.ts +3 -2
- package/dist/cjs/extensions/vitest/test-queue.d.ts +7 -6
- package/dist/cjs/predefined.d.ts +26 -21
- package/dist/cjs/predefined.js +11 -5
- package/dist/cjs/queue/queue-implementation.d.ts +8 -0
- package/dist/cjs/queue/queue-implementation.js +62 -10
- package/dist/cjs/queue/queue.d.ts +3 -1
- package/dist/cjs/queue/types.d.ts +3 -3
- package/dist/esm/connection/connection-implementation.d.ts +1 -1
- package/dist/esm/exchange/exchange-implementation.d.ts +1 -0
- package/dist/esm/exchange/exchange-implementation.js +6 -29
- package/dist/esm/exchange/exchange.d.ts +13 -12
- package/dist/esm/exchange/types.d.ts +4 -13
- package/dist/esm/exchange/types.js +1 -5
- package/dist/esm/extensions/vitest/test-batch-consumer.d.ts +3 -2
- package/dist/esm/extensions/vitest/test-channel.d.ts +17 -26
- package/dist/esm/extensions/vitest/test-connection.d.ts +12 -11
- package/dist/esm/extensions/vitest/test-consumer.d.ts +4 -3
- package/dist/esm/extensions/vitest/test-exchange.d.ts +8 -7
- package/dist/esm/extensions/vitest/test-producer.d.ts +3 -2
- package/dist/esm/extensions/vitest/test-queue.d.ts +7 -6
- package/dist/esm/predefined.d.ts +26 -21
- package/dist/esm/predefined.js +11 -5
- package/dist/esm/queue/queue-implementation.d.ts +8 -0
- package/dist/esm/queue/queue-implementation.js +60 -11
- package/dist/esm/queue/queue.d.ts +3 -1
- package/dist/esm/queue/types.d.ts +3 -3
- package/package.json +19 -14
package/README.md
CHANGED
|
@@ -25,7 +25,7 @@ npm install amqpx
|
|
|
25
25
|
## Quick example
|
|
26
26
|
|
|
27
27
|
```typescript
|
|
28
|
-
import { connect
|
|
28
|
+
import { connect } from 'amqpx'
|
|
29
29
|
|
|
30
30
|
type Order = { orderId: string; total: number }
|
|
31
31
|
|
|
@@ -36,7 +36,7 @@ const connection = await connect({
|
|
|
36
36
|
})
|
|
37
37
|
|
|
38
38
|
// Topology
|
|
39
|
-
const channel =
|
|
39
|
+
const channel = connection.createChannel()
|
|
40
40
|
const queue = await channel.createQueue('orders', { durable: true })
|
|
41
41
|
|
|
42
42
|
// Produce
|
|
@@ -44,7 +44,7 @@ const producer = await queue.createProducer<Order>()
|
|
|
44
44
|
await producer.publish({ orderId: 'abc-123', total: 49.99 })
|
|
45
45
|
|
|
46
46
|
// Consume
|
|
47
|
-
const consumer = await
|
|
47
|
+
const consumer = await queue.createConsumer<Order>({ prefetch: 10 })
|
|
48
48
|
await consumer.listen(async ({ message }) => {
|
|
49
49
|
console.log('order', message.orderId, 'total', message.total)
|
|
50
50
|
})
|
|
@@ -14,7 +14,7 @@ export declare class ConnectionImplementation extends EventEmitter<ConnectionEve
|
|
|
14
14
|
private connection;
|
|
15
15
|
private closingHandler;
|
|
16
16
|
private connectionState;
|
|
17
|
-
constructor(options: amqp.Options.Connect, retryStrategy?: RetryStrategy, socketOptions?:
|
|
17
|
+
constructor(options: amqp.Options.Connect, retryStrategy?: RetryStrategy, socketOptions?: amqp.SocketOptions | undefined);
|
|
18
18
|
connect(): Promise<this>;
|
|
19
19
|
close(timeout?: number): Promise<void>;
|
|
20
20
|
state(): ConnectionState;
|
|
@@ -9,6 +9,7 @@ export declare class ExchangeImplementation implements Exchange {
|
|
|
9
9
|
private readonly exchangeType;
|
|
10
10
|
private readonly options?;
|
|
11
11
|
private assertPromise;
|
|
12
|
+
/** Exchange bindings, re-applied when the exchange is asserted again. */
|
|
12
13
|
private bindings;
|
|
13
14
|
constructor(channel: Channel, exchangeName: string, exchangeType: ExchangeTypes, options?: ExchangeOptions);
|
|
14
15
|
assert(): Promise<this>;
|
|
@@ -18,7 +18,6 @@ const safe_stable_stringify_1 = __importDefault(require("safe-stable-stringify")
|
|
|
18
18
|
const producer_1 = require("../producer");
|
|
19
19
|
const utils_1 = require("../utils");
|
|
20
20
|
const types_1 = require("../types");
|
|
21
|
-
const types_2 = require("./types");
|
|
22
21
|
const debug = (0, util_1.debuglog)(`${utils_1.LIB_NAME}:exchange`);
|
|
23
22
|
const DEFAULT_EXCHANGE_OPTIONS = {
|
|
24
23
|
assertionMode: types_1.AssertionMode.Assert,
|
|
@@ -75,26 +74,8 @@ class ExchangeImplementation {
|
|
|
75
74
|
}
|
|
76
75
|
bindQueue(queue, pattern, args) {
|
|
77
76
|
return __awaiter(this, void 0, void 0, function* () {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
queue.name(),
|
|
81
|
-
]);
|
|
82
|
-
debug('bind-queue exchange=%s queue=%s pattern=%s', thisName, queueName, pattern);
|
|
83
|
-
const doesBindingMatch = (binding) => binding.type === types_2.BindingType.queue &&
|
|
84
|
-
binding.pattern === pattern &&
|
|
85
|
-
binding.queue === queue &&
|
|
86
|
-
(0, safe_stable_stringify_1.default)(binding.args) === (0, safe_stable_stringify_1.default)(args);
|
|
87
|
-
if (this.bindings.every(binding => !doesBindingMatch(binding))) {
|
|
88
|
-
this.bindings.push({
|
|
89
|
-
args,
|
|
90
|
-
pattern,
|
|
91
|
-
type: types_2.BindingType.queue,
|
|
92
|
-
queue,
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
const channel = yield this.channel.native();
|
|
96
|
-
yield channel.bindQueue(queueName, thisName, pattern, args);
|
|
97
|
-
debug('bind-queue-done exchange=%s queue=%s pattern=%s', thisName, queueName, pattern);
|
|
77
|
+
debug('bind-queue exchange=%s pattern=%s', this.exchangeName, pattern);
|
|
78
|
+
yield queue.bindExchange(this, pattern, args);
|
|
98
79
|
return this;
|
|
99
80
|
});
|
|
100
81
|
}
|
|
@@ -105,15 +86,13 @@ class ExchangeImplementation {
|
|
|
105
86
|
exchange.name(),
|
|
106
87
|
]);
|
|
107
88
|
debug('bind-exchange dest=%s source=%s pattern=%s', thisName, exchangeName, pattern);
|
|
108
|
-
const doesBindingMatch = (binding) => binding.
|
|
109
|
-
binding.pattern === pattern &&
|
|
89
|
+
const doesBindingMatch = (binding) => binding.pattern === pattern &&
|
|
110
90
|
binding.exchange === exchange &&
|
|
111
91
|
(0, safe_stable_stringify_1.default)(binding.args) === (0, safe_stable_stringify_1.default)(args);
|
|
112
92
|
if (this.bindings.every(binding => !doesBindingMatch(binding))) {
|
|
113
93
|
this.bindings.push({
|
|
114
94
|
args,
|
|
115
95
|
pattern,
|
|
116
|
-
type: types_2.BindingType.exchange,
|
|
117
96
|
exchange,
|
|
118
97
|
});
|
|
119
98
|
}
|
|
@@ -126,9 +105,7 @@ class ExchangeImplementation {
|
|
|
126
105
|
rebind() {
|
|
127
106
|
return __awaiter(this, void 0, void 0, function* () {
|
|
128
107
|
debug('rebind name=%s bindings=%d', this.exchangeName, this.bindings.length);
|
|
129
|
-
const promises = yield Promise.allSettled(this.bindings.map(binding => (binding.
|
|
130
|
-
? this.bindQueue(binding.queue, binding.pattern, binding.args)
|
|
131
|
-
: this.bindExchange(binding.exchange, binding.pattern, binding.args))));
|
|
108
|
+
const promises = yield Promise.allSettled(this.bindings.map(binding => this.bindExchange(binding.exchange, binding.pattern, binding.args)));
|
|
132
109
|
const failedPromise = promises.find(p => p.status === 'rejected');
|
|
133
110
|
if (failedPromise) {
|
|
134
111
|
debug('rebind-failed error=%s', (0, utils_1.errToMessage)(failedPromise.reason));
|
|
@@ -140,14 +117,14 @@ class ExchangeImplementation {
|
|
|
140
117
|
createConsumer(options_1) {
|
|
141
118
|
return __awaiter(this, arguments, void 0, function* (options, queueOptions = {}) {
|
|
142
119
|
const queue = yield this.channel.createQueue('', Object.assign(Object.assign({}, queueOptions), { durable: false, exclusive: true }));
|
|
143
|
-
yield
|
|
120
|
+
yield queue.bindExchange(this, options.pattern, options.bindingArgs);
|
|
144
121
|
return queue.createConsumer(options);
|
|
145
122
|
});
|
|
146
123
|
}
|
|
147
124
|
createBatchConsumer(options_1) {
|
|
148
125
|
return __awaiter(this, arguments, void 0, function* (options, queueOptions = {}) {
|
|
149
126
|
const queue = yield this.channel.createQueue('', Object.assign(Object.assign({}, queueOptions), { durable: false, exclusive: true }));
|
|
150
|
-
yield
|
|
127
|
+
yield queue.bindExchange(this, options.pattern, options.bindingArgs);
|
|
151
128
|
return queue.createBatchConsumer(options);
|
|
152
129
|
});
|
|
153
130
|
}
|
|
@@ -21,7 +21,9 @@ export interface Exchange {
|
|
|
21
21
|
name(): Promise<string>;
|
|
22
22
|
/**
|
|
23
23
|
* Bind a queue to this exchange.
|
|
24
|
-
* Asserts the exchange first if
|
|
24
|
+
* Asserts the queue and the exchange first if they have not been asserted yet.
|
|
25
|
+
* Equivalent to `queue.bindExchange(exchange, pattern, args)`.
|
|
26
|
+
* The binding is restored when the queue is asserted again after a reconnect.
|
|
25
27
|
* @param queue - Queue to bind to this exchange.
|
|
26
28
|
* @param pattern - Routing key pattern under which to bind.
|
|
27
29
|
* @param args - Optional AMQP headers or x-arguments for the binding.
|
|
@@ -37,25 +39,24 @@ export interface Exchange {
|
|
|
37
39
|
bindExchange(exchange: Exchange, pattern: string, args?: BindingArgs): Promise<Exchange>;
|
|
38
40
|
/**
|
|
39
41
|
* Creates a consumer for the current exchange.
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
42
|
+
* The consumer reads from a temporary exclusive queue bound to the exchange under `options.pattern`
|
|
43
|
+
* and keeps receiving messages after a reconnect.
|
|
44
|
+
* By default, creates a new dedicated channel for the consumer.
|
|
45
|
+
* Pass a channel in `options` to use a specific one instead.
|
|
44
46
|
*/
|
|
45
47
|
createConsumer<T>(options: ExchangeConsumerOptions<T>, queueOptions?: ExchangeConsumerQueueOptions): Promise<Consumer<T>>;
|
|
46
48
|
/**
|
|
47
49
|
* Creates a batch consumer for the current exchange.
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
50
|
+
* The consumer reads from a temporary exclusive queue bound to the exchange under `options.pattern`
|
|
51
|
+
* and keeps receiving messages after a reconnect.
|
|
52
|
+
* By default, creates a new dedicated channel for the consumer.
|
|
53
|
+
* Pass a channel in `options` to use a specific one instead.
|
|
52
54
|
*/
|
|
53
55
|
createBatchConsumer<T>(options: ExchangeBatchConsumerOptions<T>, queueOptions?: ExchangeConsumerQueueOptions): Promise<BatchConsumer<T>>;
|
|
54
56
|
/**
|
|
55
57
|
* Creates a producer for the current exchange.
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
* Consider using `connection.createProducerForExchange` instead.
|
|
58
|
+
* By default, creates a new dedicated channel for the producer.
|
|
59
|
+
* Pass a channel in `options` to use a specific one instead.
|
|
59
60
|
*
|
|
60
61
|
* @param options - Optional producer options (serialization, routing key, hooks, …).
|
|
61
62
|
* Set `options.isConfirmed` to `true` to open the dedicated channel in confirm mode.
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import * as amqp from 'amqplib';
|
|
2
2
|
import { AssertionMode } from '../types';
|
|
3
3
|
import { ConsumerOptions, BatchConsumerOptions } from '../consumer';
|
|
4
|
-
import { Queue } from '../queue';
|
|
5
4
|
import { Exchange } from './exchange';
|
|
6
5
|
/**
|
|
7
6
|
* The type of exchange to create. Accepted values: `'direct'`, `'fanout'`, `'topic'`, `'headers'`, `'match'`.
|
|
@@ -31,21 +30,13 @@ export type ExchangeConsumerOptions<T> = ExchangeConsumerBindingOptions & Consum
|
|
|
31
30
|
*/
|
|
32
31
|
export type ExchangeBatchConsumerOptions<T> = ExchangeConsumerBindingOptions & BatchConsumerOptions<T>;
|
|
33
32
|
export type BindingArgs = Record<string, string | number | boolean>;
|
|
34
|
-
export declare enum BindingType {
|
|
35
|
-
queue = "queue",
|
|
36
|
-
exchange = "exchange"
|
|
37
|
-
}
|
|
38
33
|
type Pattern = string;
|
|
39
|
-
|
|
34
|
+
/** A binding of another exchange to this exchange. */
|
|
35
|
+
export type ExchangeBinding = {
|
|
36
|
+
exchange: Exchange;
|
|
40
37
|
pattern: Pattern;
|
|
41
38
|
args?: BindingArgs;
|
|
42
|
-
}
|
|
43
|
-
type: BindingType.queue;
|
|
44
|
-
queue: Queue;
|
|
45
|
-
} | {
|
|
46
|
-
type: BindingType.exchange;
|
|
47
|
-
exchange: Exchange;
|
|
48
|
-
});
|
|
39
|
+
};
|
|
49
40
|
export type ExchangeOptions = amqp.Options.AssertExchange & {
|
|
50
41
|
/**
|
|
51
42
|
* Controls how the exchange is verified against the broker when `assert()` is called.
|
|
@@ -1,8 +1,2 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BindingType = void 0;
|
|
4
|
-
var BindingType;
|
|
5
|
-
(function (BindingType) {
|
|
6
|
-
BindingType["queue"] = "queue";
|
|
7
|
-
BindingType["exchange"] = "exchange";
|
|
8
|
-
})(BindingType || (exports.BindingType = BindingType = {}));
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { EventEmitter } from 'events';
|
|
2
|
+
import type { Mock } from 'vitest';
|
|
2
3
|
import type * as amqp from 'amqplib';
|
|
3
4
|
import { BatchConsumer } from '../../index';
|
|
4
5
|
import { TestQueue } from './test-queue';
|
|
@@ -32,8 +33,8 @@ import { TestChannel } from './test-channel';
|
|
|
32
33
|
*/
|
|
33
34
|
export declare class TestBatchConsumer<T> extends EventEmitter implements BatchConsumer<T> {
|
|
34
35
|
constructor();
|
|
35
|
-
close:
|
|
36
|
-
listen:
|
|
36
|
+
close: Mock;
|
|
37
|
+
listen: Mock;
|
|
37
38
|
queue: TestQueue;
|
|
38
39
|
channel: TestChannel;
|
|
39
40
|
/**
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { EventEmitter } from 'events';
|
|
2
|
+
import type { Mock } from 'vitest';
|
|
2
3
|
import { Channel, Connection } from '../../index';
|
|
4
|
+
type NativeChannelMock = Record<'cancel' | 'prefetch' | 'consume' | 'ack' | 'nack' | 'assertQueue' | 'checkQueue' | 'assertExchange' | 'checkExchange' | 'bindQueue' | 'bindExchange', Mock>;
|
|
3
5
|
/**
|
|
4
6
|
* Mock implementation of Channel using vitest mocks.
|
|
5
7
|
*
|
|
@@ -25,21 +27,21 @@ import { Channel, Connection } from '../../index';
|
|
|
25
27
|
export declare class TestChannel extends EventEmitter implements Channel {
|
|
26
28
|
readonly connection: Connection;
|
|
27
29
|
constructor(connection?: Connection);
|
|
28
|
-
connect:
|
|
29
|
-
close:
|
|
30
|
-
createExchange:
|
|
31
|
-
createQueue:
|
|
32
|
-
createProducerForQueue:
|
|
33
|
-
createProducerForExchange:
|
|
34
|
-
createConsumerForQueue:
|
|
35
|
-
createConsumerForExchange:
|
|
36
|
-
createBatchConsumerForQueue:
|
|
37
|
-
createBatchConsumerForExchange:
|
|
38
|
-
native:
|
|
30
|
+
connect: Mock;
|
|
31
|
+
close: Mock;
|
|
32
|
+
createExchange: Mock;
|
|
33
|
+
createQueue: Mock;
|
|
34
|
+
createProducerForQueue: Mock;
|
|
35
|
+
createProducerForExchange: Mock;
|
|
36
|
+
createConsumerForQueue: Mock;
|
|
37
|
+
createConsumerForExchange: Mock;
|
|
38
|
+
createBatchConsumerForQueue: Mock;
|
|
39
|
+
createBatchConsumerForExchange: Mock;
|
|
40
|
+
native: Mock;
|
|
39
41
|
private _drainPending;
|
|
40
42
|
private _drainResolvers;
|
|
41
|
-
publish:
|
|
42
|
-
checkQueue:
|
|
43
|
+
publish: Mock;
|
|
44
|
+
checkQueue: Mock;
|
|
43
45
|
/**
|
|
44
46
|
* Simulates a channel close by emitting the `close` event.
|
|
45
47
|
*/
|
|
@@ -55,17 +57,6 @@ export declare class TestChannel extends EventEmitter implements Channel {
|
|
|
55
57
|
consumeResponse: {
|
|
56
58
|
consumerTag: `${string}-${string}-${string}-${string}-${string}`;
|
|
57
59
|
};
|
|
58
|
-
nativeChannel:
|
|
59
|
-
cancel: import("vitest").Mock<import("@vitest/spy").Procedure>;
|
|
60
|
-
prefetch: import("vitest").Mock<import("@vitest/spy").Procedure>;
|
|
61
|
-
consume: import("vitest").Mock<import("@vitest/spy").Procedure>;
|
|
62
|
-
ack: import("vitest").Mock<import("@vitest/spy").Procedure>;
|
|
63
|
-
nack: import("vitest").Mock<import("@vitest/spy").Procedure>;
|
|
64
|
-
assertQueue: import("vitest").Mock<import("@vitest/spy").Procedure>;
|
|
65
|
-
checkQueue: import("vitest").Mock<import("@vitest/spy").Procedure>;
|
|
66
|
-
assertExchange: import("vitest").Mock<import("@vitest/spy").Procedure>;
|
|
67
|
-
checkExchange: import("vitest").Mock<import("@vitest/spy").Procedure>;
|
|
68
|
-
bindQueue: import("vitest").Mock<import("@vitest/spy").Procedure>;
|
|
69
|
-
bindExchange: import("vitest").Mock<import("@vitest/spy").Procedure>;
|
|
70
|
-
};
|
|
60
|
+
nativeChannel: NativeChannelMock;
|
|
71
61
|
}
|
|
62
|
+
export {};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { EventEmitter } from 'events';
|
|
2
|
+
import type { Mock } from 'vitest';
|
|
2
3
|
import { Connection } from '../../index';
|
|
3
4
|
/**
|
|
4
5
|
* Mock implementation of Connection using vitest mocks.
|
|
@@ -20,17 +21,17 @@ import { Connection } from '../../index';
|
|
|
20
21
|
* ```
|
|
21
22
|
*/
|
|
22
23
|
export declare class TestConnection extends EventEmitter implements Connection {
|
|
23
|
-
close:
|
|
24
|
-
connect:
|
|
25
|
-
createChannel:
|
|
26
|
-
createConsumerForExchange:
|
|
27
|
-
createConsumerForQueue:
|
|
28
|
-
createBatchConsumerForQueue:
|
|
29
|
-
createBatchConsumerForExchange:
|
|
30
|
-
createProducerForExchange:
|
|
31
|
-
createProducerForQueue:
|
|
32
|
-
native:
|
|
33
|
-
state:
|
|
24
|
+
close: Mock;
|
|
25
|
+
connect: Mock;
|
|
26
|
+
createChannel: Mock;
|
|
27
|
+
createConsumerForExchange: Mock;
|
|
28
|
+
createConsumerForQueue: Mock;
|
|
29
|
+
createBatchConsumerForQueue: Mock;
|
|
30
|
+
createBatchConsumerForExchange: Mock;
|
|
31
|
+
createProducerForExchange: Mock;
|
|
32
|
+
createProducerForQueue: Mock;
|
|
33
|
+
native: Mock;
|
|
34
|
+
state: Mock;
|
|
34
35
|
/**
|
|
35
36
|
* Simulates a server-side disconnect by emitting the `reconnecting` event.
|
|
36
37
|
*/
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { EventEmitter } from 'events';
|
|
2
|
+
import type { Mock } from 'vitest';
|
|
2
3
|
import type * as amqp from 'amqplib';
|
|
3
4
|
import { Consumer } from '../../index';
|
|
4
5
|
import { TestQueue } from './test-queue';
|
|
@@ -32,9 +33,9 @@ import { TestChannel } from './test-channel';
|
|
|
32
33
|
*/
|
|
33
34
|
export declare class TestConsumer<T> extends EventEmitter implements Consumer<T> {
|
|
34
35
|
constructor();
|
|
35
|
-
close:
|
|
36
|
-
listen:
|
|
37
|
-
setPrefetch:
|
|
36
|
+
close: Mock;
|
|
37
|
+
listen: Mock;
|
|
38
|
+
setPrefetch: Mock;
|
|
38
39
|
queue: TestQueue;
|
|
39
40
|
channel: TestChannel;
|
|
40
41
|
/**
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Mock } from 'vitest';
|
|
1
2
|
import { Exchange } from '../../index';
|
|
2
3
|
/**
|
|
3
4
|
* Mock implementation of Exchange using vitest mocks.
|
|
@@ -16,11 +17,11 @@ import { Exchange } from '../../index';
|
|
|
16
17
|
* ```
|
|
17
18
|
*/
|
|
18
19
|
export declare class TestExchange implements Exchange {
|
|
19
|
-
assert:
|
|
20
|
-
name:
|
|
21
|
-
bindQueue:
|
|
22
|
-
bindExchange:
|
|
23
|
-
createConsumer:
|
|
24
|
-
createBatchConsumer:
|
|
25
|
-
createProducer:
|
|
20
|
+
assert: Mock;
|
|
21
|
+
name: Mock;
|
|
22
|
+
bindQueue: Mock;
|
|
23
|
+
bindExchange: Mock;
|
|
24
|
+
createConsumer: Mock;
|
|
25
|
+
createBatchConsumer: Mock;
|
|
26
|
+
createProducer: Mock;
|
|
26
27
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { EventEmitter } from 'events';
|
|
2
|
+
import type { Mock } from 'vitest';
|
|
2
3
|
import { Producer } from '../../index';
|
|
3
4
|
import { TestChannel } from './test-channel';
|
|
4
5
|
/**
|
|
@@ -24,8 +25,8 @@ import { TestChannel } from './test-channel';
|
|
|
24
25
|
*/
|
|
25
26
|
export declare class TestProducer<T> extends EventEmitter implements Producer<T> {
|
|
26
27
|
constructor();
|
|
27
|
-
close:
|
|
28
|
-
publish:
|
|
28
|
+
close: Mock;
|
|
29
|
+
publish: Mock;
|
|
29
30
|
channel: TestChannel;
|
|
30
31
|
/**
|
|
31
32
|
* Returns the first argument (the message payload) from every `publish` call recorded so far.
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Mock } from 'vitest';
|
|
1
2
|
import { Queue } from '../../index';
|
|
2
3
|
/**
|
|
3
4
|
* Mock implementation of Queue using vitest mocks.
|
|
@@ -16,10 +17,10 @@ import { Queue } from '../../index';
|
|
|
16
17
|
* ```
|
|
17
18
|
*/
|
|
18
19
|
export declare class TestQueue implements Queue {
|
|
19
|
-
assert:
|
|
20
|
-
name:
|
|
21
|
-
bindExchange:
|
|
22
|
-
createConsumer:
|
|
23
|
-
createBatchConsumer:
|
|
24
|
-
createProducer:
|
|
20
|
+
assert: Mock;
|
|
21
|
+
name: Mock;
|
|
22
|
+
bindExchange: Mock;
|
|
23
|
+
createConsumer: Mock;
|
|
24
|
+
createBatchConsumer: Mock;
|
|
25
|
+
createProducer: Mock;
|
|
25
26
|
}
|
package/dist/cjs/predefined.d.ts
CHANGED
|
@@ -1,49 +1,54 @@
|
|
|
1
1
|
import { Exchange } from './exchange';
|
|
2
2
|
import { Channel } from './channel';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Returns the direct exchange that RabbitMQ creates by default in every virtual host.
|
|
5
5
|
*
|
|
6
|
-
* The
|
|
6
|
+
* The exchange has name *amq.direct*, is durable, and has type *direct*.
|
|
7
|
+
* The exchange always exists on the broker, so it is never declared.
|
|
7
8
|
*
|
|
8
|
-
* @param channel The channel
|
|
9
|
-
* @returns The exchange
|
|
9
|
+
* @param channel The channel the exchange belongs to
|
|
10
|
+
* @returns The predefined exchange
|
|
10
11
|
*/
|
|
11
12
|
export declare const directExchange: (channel: Channel) => Exchange;
|
|
12
13
|
/**
|
|
13
|
-
*
|
|
14
|
+
* Returns the fanout exchange that RabbitMQ creates by default in every virtual host.
|
|
14
15
|
*
|
|
15
|
-
* The
|
|
16
|
+
* The exchange has name *amq.fanout*, is durable, and has type *fanout*.
|
|
17
|
+
* The exchange always exists on the broker, so it is never declared.
|
|
16
18
|
*
|
|
17
|
-
* @param channel The channel
|
|
18
|
-
* @returns The exchange
|
|
19
|
+
* @param channel The channel the exchange belongs to
|
|
20
|
+
* @returns The predefined exchange
|
|
19
21
|
*/
|
|
20
22
|
export declare const fanoutExchange: (channel: Channel) => Exchange;
|
|
21
23
|
/**
|
|
22
|
-
*
|
|
24
|
+
* Returns the headers exchange that RabbitMQ creates by default in every virtual host.
|
|
23
25
|
*
|
|
24
|
-
* The
|
|
26
|
+
* The exchange has name *amq.headers*, is durable, and has type *headers*.
|
|
27
|
+
* The exchange always exists on the broker, so it is never declared.
|
|
25
28
|
*
|
|
26
|
-
* @param channel The channel
|
|
27
|
-
* @returns The exchange
|
|
29
|
+
* @param channel The channel the exchange belongs to
|
|
30
|
+
* @returns The predefined exchange
|
|
28
31
|
*/
|
|
29
32
|
export declare const headersExchange: (channel: Channel) => Exchange;
|
|
30
33
|
/**
|
|
31
|
-
*
|
|
32
|
-
* Behaves the same as
|
|
34
|
+
* Returns the match exchange that RabbitMQ creates by default in every virtual host.
|
|
35
|
+
* Behaves the same as {@link headersExchange}, but has a different name.
|
|
33
36
|
*
|
|
34
|
-
* The
|
|
37
|
+
* The exchange has name *amq.match*, is durable, and has type *headers*.
|
|
38
|
+
* The exchange always exists on the broker, so it is never declared.
|
|
35
39
|
*
|
|
36
|
-
* @param channel The channel
|
|
37
|
-
* @returns The exchange
|
|
40
|
+
* @param channel The channel the exchange belongs to
|
|
41
|
+
* @returns The predefined exchange
|
|
38
42
|
*/
|
|
39
43
|
export declare const matchExchange: (channel: Channel) => Exchange;
|
|
40
44
|
/**
|
|
41
|
-
*
|
|
45
|
+
* Returns the topic exchange that RabbitMQ creates by default in every virtual host.
|
|
42
46
|
*
|
|
43
|
-
* The
|
|
47
|
+
* The exchange has name *amq.topic*, is durable, and has type *topic*.
|
|
48
|
+
* The exchange always exists on the broker, so it is never declared.
|
|
44
49
|
*
|
|
45
|
-
* @param channel The channel
|
|
46
|
-
* @returns The exchange
|
|
50
|
+
* @param channel The channel the exchange belongs to
|
|
51
|
+
* @returns The predefined exchange
|
|
47
52
|
*/
|
|
48
53
|
export declare const topicExchange: (channel: Channel) => Exchange;
|
|
49
54
|
/**
|
package/dist/cjs/predefined.js
CHANGED
|
@@ -3,24 +3,30 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.defaultExchange = exports.topicExchange = exports.matchExchange = exports.headersExchange = exports.fanoutExchange = exports.directExchange = void 0;
|
|
4
4
|
const exchange_1 = require("./exchange");
|
|
5
5
|
const default_exchange_1 = require("./exchange/default-exchange");
|
|
6
|
-
const
|
|
6
|
+
const types_1 = require("./types");
|
|
7
|
+
const directExchange = (channel) => new exchange_1.ExchangeImplementation(channel, 'amq.direct', 'direct', {
|
|
7
8
|
durable: true,
|
|
9
|
+
assertionMode: types_1.AssertionMode.Passive,
|
|
8
10
|
});
|
|
9
11
|
exports.directExchange = directExchange;
|
|
10
|
-
const fanoutExchange = (channel) => new exchange_1.ExchangeImplementation(channel, '
|
|
12
|
+
const fanoutExchange = (channel) => new exchange_1.ExchangeImplementation(channel, 'amq.fanout', 'fanout', {
|
|
11
13
|
durable: true,
|
|
14
|
+
assertionMode: types_1.AssertionMode.Passive,
|
|
12
15
|
});
|
|
13
16
|
exports.fanoutExchange = fanoutExchange;
|
|
14
|
-
const headersExchange = (channel) => new exchange_1.ExchangeImplementation(channel, '
|
|
17
|
+
const headersExchange = (channel) => new exchange_1.ExchangeImplementation(channel, 'amq.headers', 'headers', {
|
|
15
18
|
durable: true,
|
|
19
|
+
assertionMode: types_1.AssertionMode.Passive,
|
|
16
20
|
});
|
|
17
21
|
exports.headersExchange = headersExchange;
|
|
18
|
-
const matchExchange = (channel) => new exchange_1.ExchangeImplementation(channel, '
|
|
22
|
+
const matchExchange = (channel) => new exchange_1.ExchangeImplementation(channel, 'amq.match', 'headers', {
|
|
19
23
|
durable: true,
|
|
24
|
+
assertionMode: types_1.AssertionMode.Passive,
|
|
20
25
|
});
|
|
21
26
|
exports.matchExchange = matchExchange;
|
|
22
|
-
const topicExchange = (channel) => new exchange_1.ExchangeImplementation(channel, '
|
|
27
|
+
const topicExchange = (channel) => new exchange_1.ExchangeImplementation(channel, 'amq.topic', 'topic', {
|
|
23
28
|
durable: true,
|
|
29
|
+
assertionMode: types_1.AssertionMode.Passive,
|
|
24
30
|
});
|
|
25
31
|
exports.topicExchange = topicExchange;
|
|
26
32
|
const defaultExchange = (channel) => new default_exchange_1.DefaultExchange(channel);
|
|
@@ -9,10 +9,18 @@ export declare class QueueImplementation implements Queue {
|
|
|
9
9
|
private readonly queueName;
|
|
10
10
|
private readonly options?;
|
|
11
11
|
private assertPromise;
|
|
12
|
+
/** Queue name resolved by the last assert; null until then and after the channel closes. */
|
|
13
|
+
private declaredName;
|
|
14
|
+
private bindings;
|
|
12
15
|
constructor(channel: Channel, queueName: string, options?: QueueOptions);
|
|
13
16
|
assert(): Promise<this>;
|
|
14
17
|
name(): Promise<string>;
|
|
15
18
|
bindExchange(exchange: Exchange, pattern: string, args?: BindingArgs): Promise<this>;
|
|
19
|
+
/** Creates the binding on the broker; the queue must already be asserted. */
|
|
20
|
+
private nativeBind;
|
|
21
|
+
private currentName;
|
|
22
|
+
/** Re-applies the remembered bindings after the queue is asserted. */
|
|
23
|
+
private rebind;
|
|
16
24
|
createConsumer<T>(options?: ConsumerOptions<T>): Promise<Consumer<T>>;
|
|
17
25
|
createBatchConsumer<T>(options?: BatchConsumerOptions<T>): Promise<BatchConsumer<T>>;
|
|
18
26
|
createProducer<T>(options?: ProducerOptions<T> & {
|