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.
Files changed (40) hide show
  1. package/README.md +3 -3
  2. package/dist/cjs/connection/connection-implementation.d.ts +1 -1
  3. package/dist/cjs/exchange/exchange-implementation.d.ts +1 -0
  4. package/dist/cjs/exchange/exchange-implementation.js +6 -29
  5. package/dist/cjs/exchange/exchange.d.ts +13 -12
  6. package/dist/cjs/exchange/types.d.ts +4 -13
  7. package/dist/cjs/exchange/types.js +0 -6
  8. package/dist/cjs/extensions/vitest/test-batch-consumer.d.ts +3 -2
  9. package/dist/cjs/extensions/vitest/test-channel.d.ts +17 -26
  10. package/dist/cjs/extensions/vitest/test-connection.d.ts +12 -11
  11. package/dist/cjs/extensions/vitest/test-consumer.d.ts +4 -3
  12. package/dist/cjs/extensions/vitest/test-exchange.d.ts +8 -7
  13. package/dist/cjs/extensions/vitest/test-producer.d.ts +3 -2
  14. package/dist/cjs/extensions/vitest/test-queue.d.ts +7 -6
  15. package/dist/cjs/predefined.d.ts +26 -21
  16. package/dist/cjs/predefined.js +11 -5
  17. package/dist/cjs/queue/queue-implementation.d.ts +8 -0
  18. package/dist/cjs/queue/queue-implementation.js +62 -10
  19. package/dist/cjs/queue/queue.d.ts +3 -1
  20. package/dist/cjs/queue/types.d.ts +3 -3
  21. package/dist/esm/connection/connection-implementation.d.ts +1 -1
  22. package/dist/esm/exchange/exchange-implementation.d.ts +1 -0
  23. package/dist/esm/exchange/exchange-implementation.js +6 -29
  24. package/dist/esm/exchange/exchange.d.ts +13 -12
  25. package/dist/esm/exchange/types.d.ts +4 -13
  26. package/dist/esm/exchange/types.js +1 -5
  27. package/dist/esm/extensions/vitest/test-batch-consumer.d.ts +3 -2
  28. package/dist/esm/extensions/vitest/test-channel.d.ts +17 -26
  29. package/dist/esm/extensions/vitest/test-connection.d.ts +12 -11
  30. package/dist/esm/extensions/vitest/test-consumer.d.ts +4 -3
  31. package/dist/esm/extensions/vitest/test-exchange.d.ts +8 -7
  32. package/dist/esm/extensions/vitest/test-producer.d.ts +3 -2
  33. package/dist/esm/extensions/vitest/test-queue.d.ts +7 -6
  34. package/dist/esm/predefined.d.ts +26 -21
  35. package/dist/esm/predefined.js +11 -5
  36. package/dist/esm/queue/queue-implementation.d.ts +8 -0
  37. package/dist/esm/queue/queue-implementation.js +60 -11
  38. package/dist/esm/queue/queue.d.ts +3 -1
  39. package/dist/esm/queue/types.d.ts +3 -3
  40. 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, AssertionMode } from 'amqpx'
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 = await connection.createChannel()
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 consumerQueue.createConsumer<Order>({ prefetch: 10 })
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?: unknown | undefined);
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
- const [thisName, queueName] = yield Promise.all([
79
- this.name(),
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.type === types_2.BindingType.exchange &&
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.type === types_2.BindingType.queue
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 this.bindQueue(queue, options.pattern, options.bindingArgs);
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 this.bindQueue(queue, options.pattern, options.bindingArgs);
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 it has not been asserted yet.
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
- * Internally asserts an exclusive queue and binds it to the exchange.
41
- * Unless specified otherwise, uses the same channel as was used to declare the exchange.
42
- * This is generally not recommended, as each consumer should have its own dedicated channel.
43
- * Consider using `connection.createConsumerForExchange` instead.
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
- * Internally asserts an exclusive queue and binds it to the exchange.
49
- * Unless specified otherwise, uses the same channel as was used to declare the exchange.
50
- * This is generally not recommended, as each consumer should have its own dedicated channel.
51
- * Consider using `connection.createBatchConsumerForExchange` instead.
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
- * Unless specified otherwise, uses the same channel as was used to declare the exchange.
57
- * This is generally not recommended, as each producer should have its own dedicated channel.
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
- export type Binding = {
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: import("vitest").Mock<import("@vitest/spy").Procedure>;
36
- listen: import("vitest").Mock<import("@vitest/spy").Procedure>;
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: import("vitest").Mock<import("@vitest/spy").Procedure>;
29
- close: import("vitest").Mock<import("@vitest/spy").Procedure>;
30
- createExchange: import("vitest").Mock<import("@vitest/spy").Procedure>;
31
- createQueue: import("vitest").Mock<import("@vitest/spy").Procedure>;
32
- createProducerForQueue: import("vitest").Mock<import("@vitest/spy").Procedure>;
33
- createProducerForExchange: import("vitest").Mock<import("@vitest/spy").Procedure>;
34
- createConsumerForQueue: import("vitest").Mock<import("@vitest/spy").Procedure>;
35
- createConsumerForExchange: import("vitest").Mock<import("@vitest/spy").Procedure>;
36
- createBatchConsumerForQueue: import("vitest").Mock<import("@vitest/spy").Procedure>;
37
- createBatchConsumerForExchange: import("vitest").Mock<import("@vitest/spy").Procedure>;
38
- native: import("vitest").Mock<import("@vitest/spy").Procedure>;
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: import("vitest").Mock<import("@vitest/spy").Procedure>;
42
- checkQueue: import("vitest").Mock<import("@vitest/spy").Procedure>;
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: import("vitest").Mock<import("@vitest/spy").Procedure>;
24
- connect: import("vitest").Mock<import("@vitest/spy").Procedure>;
25
- createChannel: import("vitest").Mock<import("@vitest/spy").Procedure>;
26
- createConsumerForExchange: import("vitest").Mock<import("@vitest/spy").Procedure>;
27
- createConsumerForQueue: import("vitest").Mock<import("@vitest/spy").Procedure>;
28
- createBatchConsumerForQueue: import("vitest").Mock<import("@vitest/spy").Procedure>;
29
- createBatchConsumerForExchange: import("vitest").Mock<import("@vitest/spy").Procedure>;
30
- createProducerForExchange: import("vitest").Mock<import("@vitest/spy").Procedure>;
31
- createProducerForQueue: import("vitest").Mock<import("@vitest/spy").Procedure>;
32
- native: import("vitest").Mock<import("@vitest/spy").Procedure>;
33
- state: import("vitest").Mock<import("@vitest/spy").Procedure>;
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: import("vitest").Mock<import("@vitest/spy").Procedure>;
36
- listen: import("vitest").Mock<import("@vitest/spy").Procedure>;
37
- setPrefetch: import("vitest").Mock<import("@vitest/spy").Procedure>;
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: import("vitest").Mock<import("@vitest/spy").Procedure>;
20
- name: import("vitest").Mock<import("@vitest/spy").Procedure>;
21
- bindQueue: import("vitest").Mock<import("@vitest/spy").Procedure>;
22
- bindExchange: import("vitest").Mock<import("@vitest/spy").Procedure>;
23
- createConsumer: import("vitest").Mock<import("@vitest/spy").Procedure>;
24
- createBatchConsumer: import("vitest").Mock<import("@vitest/spy").Procedure>;
25
- createProducer: import("vitest").Mock<import("@vitest/spy").Procedure>;
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: import("vitest").Mock<import("@vitest/spy").Procedure>;
28
- publish: import("vitest").Mock<import("@vitest/spy").Procedure>;
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: import("vitest").Mock<import("@vitest/spy").Procedure>;
20
- name: import("vitest").Mock<import("@vitest/spy").Procedure>;
21
- bindExchange: import("vitest").Mock<import("@vitest/spy").Procedure>;
22
- createConsumer: import("vitest").Mock<import("@vitest/spy").Procedure>;
23
- createBatchConsumer: import("vitest").Mock<import("@vitest/spy").Procedure>;
24
- createProducer: import("vitest").Mock<import("@vitest/spy").Procedure>;
20
+ assert: Mock;
21
+ name: Mock;
22
+ bindExchange: Mock;
23
+ createConsumer: Mock;
24
+ createBatchConsumer: Mock;
25
+ createProducer: Mock;
25
26
  }
@@ -1,49 +1,54 @@
1
1
  import { Exchange } from './exchange';
2
2
  import { Channel } from './channel';
3
3
  /**
4
- * This will create a direct exchange that is created by default by RabbitMQ container.
4
+ * Returns the direct exchange that RabbitMQ creates by default in every virtual host.
5
5
  *
6
- * The direct exchange has name *amqp.direct*, is durable, and has type *direct*.
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 that should assert the exchange
9
- * @returns The exchange that was created
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
- * This will create a fanout exchange that is created by default by RabbitMQ container.
14
+ * Returns the fanout exchange that RabbitMQ creates by default in every virtual host.
14
15
  *
15
- * The fanout exchange has name *amqp.fanout*, is durable, and has type *fanout*.
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 that should assert the exchange
18
- * @returns The exchange that was created
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
- * This will create a headers exchange that is created by default by RabbitMQ container.
24
+ * Returns the headers exchange that RabbitMQ creates by default in every virtual host.
23
25
  *
24
- * The headers exchange has name *amqp.headers*, is durable, and has type *headers*.
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 that should assert the exchange
27
- * @returns The exchange that was created
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
- * This will create a match exchange that is created by default by RabbitMQ container.
32
- * Behaves the same as headers exchange, but has a different name.
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 match exchange has name *amqp.match*, is durable, and has type *match*.
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 that should assert the exchange
37
- * @returns The exchange that was created
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
- * This will create a topic exchange that is created by default by RabbitMQ container.
45
+ * Returns the topic exchange that RabbitMQ creates by default in every virtual host.
42
46
  *
43
- * The topic exchange has name *amqp.topic*, is durable, and has type *topic*.
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 that should assert the exchange
46
- * @returns The exchange that was created
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
  /**
@@ -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 directExchange = (channel) => new exchange_1.ExchangeImplementation(channel, 'amqp.direct', 'direct', {
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, 'amqp.fanout', 'fanout', {
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, 'amqp.headers', 'headers', {
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, 'amqp.match', 'match', {
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, 'amqp.topic', 'topic', {
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> & {