@droidsolutions-oss/amqp-ts 3.0.4 → 4.0.0-develop.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.
Files changed (48) hide show
  1. package/README.md +186 -45
  2. package/lib/AmqpProperties.js +1 -2
  3. package/lib/Binding.d.ts +36 -6
  4. package/lib/Binding.js +244 -75
  5. package/lib/Binding.js.map +1 -1
  6. package/lib/Connection/Connection.d.ts +87 -46
  7. package/lib/Connection/Connection.js +360 -181
  8. package/lib/Connection/Connection.js.map +1 -1
  9. package/lib/Connection/ConnectionMetrics.js +1 -2
  10. package/lib/Connection/RecoveryOptions.d.ts +6 -0
  11. package/lib/Connection/RecoveryOptions.js +2 -0
  12. package/lib/Connection/RecoveryOptions.js.map +1 -0
  13. package/lib/Connection/Topology.d.ts +1 -1
  14. package/lib/Connection/Topology.js +1 -2
  15. package/lib/Deferred.d.ts +18 -0
  16. package/lib/Deferred.js +33 -0
  17. package/lib/Deferred.js.map +1 -0
  18. package/lib/Exchange/DeclarationOptions.js +1 -2
  19. package/lib/Exchange/Exchange.d.ts +38 -17
  20. package/lib/Exchange/Exchange.js +204 -159
  21. package/lib/Exchange/Exchange.js.map +1 -1
  22. package/lib/Exchange/ExchangeType.js +1 -2
  23. package/lib/Exchange/InitializeResult.js +1 -2
  24. package/lib/LoggerFactory.js +1 -5
  25. package/lib/LoggerFactory.js.map +1 -1
  26. package/lib/Message.d.ts +11 -10
  27. package/lib/Message.js +66 -37
  28. package/lib/Message.js.map +1 -1
  29. package/lib/Queue/DeclarationOptions.js +1 -2
  30. package/lib/Queue/DeleteResult.js +1 -2
  31. package/lib/Queue/InitializeResult.js +1 -2
  32. package/lib/Queue/Queue.d.ts +87 -26
  33. package/lib/Queue/Queue.js +440 -207
  34. package/lib/Queue/Queue.js.map +1 -1
  35. package/lib/Queue/StartConsumerResult.js +1 -2
  36. package/lib/amqp-ts.d.ts +0 -1
  37. package/lib/amqp-ts.js +2 -7
  38. package/lib/amqp-ts.js.map +1 -1
  39. package/lib/errorMessage.d.ts +1 -0
  40. package/lib/errorMessage.js +18 -0
  41. package/lib/errorMessage.js.map +1 -0
  42. package/lib/index.d.ts +19 -14
  43. package/lib/index.js +7 -13
  44. package/lib/index.js.map +1 -1
  45. package/package.json +38 -60
  46. package/lib/Connection/ReconnectStrategy.d.ts +0 -4
  47. package/lib/Connection/ReconnectStrategy.js +0 -3
  48. package/lib/Connection/ReconnectStrategy.js.map +0 -1
package/lib/Binding.js CHANGED
@@ -1,14 +1,13 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Binding = void 0;
4
- const Queue_1 = require("./Queue/Queue");
5
- class Binding {
1
+ import { Queue } from "./Queue/Queue.js";
2
+ export class Binding {
3
+ pattern;
4
+ args;
6
5
  static id(destination, source, pattern) {
7
6
  pattern = pattern || "";
8
7
  return ("[" +
9
8
  source.name +
10
9
  "]to" +
11
- (destination instanceof Queue_1.Queue ? "Queue" : "Exchange") +
10
+ (destination instanceof Queue ? "Queue" : "Exchange") +
12
11
  "[" +
13
12
  destination.name +
14
13
  "]" +
@@ -25,88 +24,258 @@ class Binding {
25
24
  }
26
25
  return Promise.all(promises);
27
26
  }
27
+ /**
28
+ * A promise that resolves once the binding is created. It is replaced by a pending promise while the binding is
29
+ * created again after a lost connection. It rejects when the binding or one of its ends fails on its own, or when
30
+ * the connection is closed or recovery gives up while it is pending.
31
+ */
32
+ initialized;
33
+ /** @internal */
34
+ _source;
35
+ /** @internal */
36
+ _destination;
37
+ log;
38
+ _deferred;
39
+ /** The generation of the last initialization, and that initialization. */
40
+ _generation;
41
+ _initializing = Promise.resolve();
42
+ /** Changes with every initialization, so a superseded one can tell. */
43
+ _attempt = 0;
44
+ /** The creation of the binding on the broker that is in flight, if any. Never rejects. */
45
+ _creating = Promise.resolve();
46
+ /** Set once {@link delete} was called, after which nothing creates the binding again. */
47
+ _deleting;
28
48
  constructor(destination, source, pattern = "", args = {}) {
29
49
  this.pattern = pattern;
30
50
  this.args = args;
31
51
  this.log = destination.connection.loggerFactory(this.constructor);
32
52
  this._source = source;
33
53
  this._destination = destination;
34
- this._destination.connection._bindings[Binding.id(this._destination, this._source, this.pattern)] = this;
35
- this._initialize();
36
- }
37
- _initialize() {
38
- this.initialized = new Promise((resolve, reject) => {
39
- if (this._destination instanceof Queue_1.Queue) {
40
- const queue = this._destination;
41
- queue.initialized.then(() => {
42
- queue._channel.bindQueue(this._destination.name, this._source.name, this.pattern, this.args, (err, _ok) => {
43
- /* istanbul ignore if */
44
- if (err) {
45
- this.log.error({ err }, "Failed to create queue binding (%s->%s)", this._source.name, this._destination.name);
46
- delete this._destination.connection._bindings[Binding.id(this._destination, this._source, this.pattern)];
47
- reject(err);
48
- }
49
- else {
50
- resolve(this);
51
- }
52
- });
53
- });
54
+ const connection = this._destination.connection;
55
+ this._deferred = connection._createDeferred();
56
+ this.initialized = this._deferred.promise;
57
+ connection._bindings[this._id] = this;
58
+ connection._forgetFailure(this);
59
+ // while disconnected the next connect initializes it
60
+ if (connection._model) {
61
+ this._initialize(connection._model, connection._generation).catch(() => { });
62
+ }
63
+ }
64
+ /**
65
+ * Creates the binding on a short-lived channel of the given model once source and destination are initialized on
66
+ * the given generation, then settles {@link initialized}. Does nothing if the binding was already initialized for the
67
+ * given generation. A source on another connection is only waited for, its own connection initializes it.
68
+ * @internal
69
+ */
70
+ _initialize(model, generation) {
71
+ if (this._deleting !== undefined) {
72
+ return this._initializing;
73
+ }
74
+ if (this._generation !== generation) {
75
+ this._generation = generation;
76
+ this._initializing = this._bind(model, generation, ++this._attempt);
77
+ }
78
+ return this._initializing;
79
+ }
80
+ /**
81
+ * Creates every binding from or to the given entity again. Used after the entity's channel closed and the entity
82
+ * was declared again, because a broker-side delete of an exchange or queue removes its bindings as well. Never
83
+ * rejects, every binding handles its own failure. Only the bindings kept by the entity's own connection are created
84
+ * again, so the given model is always that of their destination's connection.
85
+ * @internal
86
+ */
87
+ static async _rebindContaining(connectionPoint, model) {
88
+ const bindings = Object.values(connectionPoint.connection._bindings).filter((binding) => binding._source === connectionPoint || binding._destination === connectionPoint);
89
+ await Promise.allSettled(bindings.map((binding) => binding._rebind(model)));
90
+ }
91
+ /**
92
+ * Creates the binding again on a short-lived channel of the given model, then resolves {@link initialized}. Unlike
93
+ * {@link _initialize} it does not wait for source and destination.
94
+ *
95
+ * A failure is never final. The other end may be gone at this moment (for example an autoDelete exchange the broker
96
+ * removed together with the queue), so the binding stays declared and {@link initialized} stays pending until the
97
+ * other end re-initializes, which re-binds, or the next connect does. It also does not supersede a running
98
+ * {@link _initialize}, which may still be waiting for a freshly declared end.
99
+ *
100
+ * A binding that was deleted or replaced by binding the same pair again meanwhile is settled right away, since
101
+ * nothing would create it again.
102
+ * @internal
103
+ */
104
+ async _rebind(model) {
105
+ const destination = this._destination;
106
+ const source = this._source;
107
+ const connection = destination.connection;
108
+ if (this._deleting !== undefined) {
109
+ return;
110
+ }
111
+ this._invalidate();
112
+ try {
113
+ await this._create(model);
114
+ if (!connection._isModelClosed(model)) {
115
+ this._deferred.resolve(this);
116
+ }
117
+ else if (!this._isDeclared) {
118
+ this._deferred.reject(new Error("Connection closed while the binding was created"));
119
+ }
120
+ }
121
+ catch (err) {
122
+ if (!this._isDeclared) {
123
+ this._deferred.reject(err);
124
+ return;
54
125
  }
55
- else {
56
- const exchange = this._destination;
57
- exchange.initialized.then(() => {
58
- exchange._channel.bindExchange(this._destination.name, this._source.name, this.pattern, this.args, (err, _ok) => {
59
- /* istanbul ignore if */
60
- if (err) {
61
- this.log.error({ err }, "Failed to create exchange binding (%s->%s)", this._source.name, this._destination.name);
62
- delete this._destination.connection._bindings[Binding.id(this._destination, this._source, this.pattern)];
63
- reject(err);
64
- }
65
- else {
66
- resolve(this);
67
- }
68
- });
69
- });
126
+ if (connection._isModelClosed(model)) {
127
+ // the next connect initializes it again, until then initialized stays pending
128
+ return;
70
129
  }
71
- });
130
+ this.log.warn({ err }, "Cannot re-create binding (%s->%s) yet, retrying when either end is declared again or on the next connect.", source.name, destination.name);
131
+ }
132
+ }
133
+ /** @internal */
134
+ get _id() {
135
+ return Binding.id(this._destination, this._source, this.pattern);
136
+ }
137
+ /** Whether this binding is still declared, i.e. neither deleted, replaced nor removed together with a failed end. */
138
+ get _isDeclared() {
139
+ return this._destination.connection._bindings[this._id] === this;
72
140
  }
73
141
  /**
74
- * Deletes this binding of either a queue or an exchange.
142
+ * Replaces a settled {@link initialized} with a pending one, until the binding is created again.
143
+ * @internal
75
144
  */
76
- delete() {
77
- return new Promise((resolve, reject) => {
78
- if (this._destination instanceof Queue_1.Queue) {
79
- const queue = this._destination;
80
- queue.initialized.then(() => {
81
- queue._channel.unbindQueue(this._destination.name, this._source.name, this.pattern, this.args, (err, _ok) => {
82
- /* istanbul ignore if */
83
- if (err) {
84
- reject(err);
85
- }
86
- else {
87
- delete this._destination.connection._bindings[Binding.id(this._destination, this._source, this.pattern)];
88
- resolve(null);
89
- }
90
- });
91
- });
145
+ _invalidate() {
146
+ if (this._deferred.settled) {
147
+ this._deferred = this._destination.connection._createDeferred();
148
+ this.initialized = this._deferred.promise;
149
+ }
150
+ }
151
+ /**
152
+ * Rejects {@link initialized} if it is still pending. Used when the connection is closed, recovery gave up or an end
153
+ * of the binding failed.
154
+ * @internal
155
+ */
156
+ _rejectPending(err) {
157
+ if (!this._deferred.settled) {
158
+ this._deferred.reject(err);
159
+ }
160
+ }
161
+ /**
162
+ * Whether the source exchange belongs to another connection than the destination. The binding belongs to the
163
+ * destination's connection, while the source is initialized and recovered by its own connection only.
164
+ * @internal
165
+ */
166
+ get _isCrossConnection() {
167
+ return this._source.connection !== this._destination.connection;
168
+ }
169
+ /**
170
+ * Creates the binding on a short-lived channel of the given model. The creation is tracked, so {@link delete} can
171
+ * wait for it instead of unbinding before it.
172
+ */
173
+ _create(model) {
174
+ const destination = this._destination;
175
+ const source = this._source;
176
+ const creating = this._onOwnChannel(model, "Binding", (channel) => destination instanceof Queue
177
+ ? channel.bindQueue(destination.name, source.name, this.pattern, this.args)
178
+ : channel.bindExchange(destination.name, source.name, this.pattern, this.args));
179
+ this._creating = creating.then(() => { }, () => { });
180
+ return creating;
181
+ }
182
+ /**
183
+ * Runs a bind or unbind on a short-lived channel of the given model. A failing bind or unbind closes the channel it
184
+ * runs on, so it must not be the destination's channel, which would then re-initialize, nor one shared with other
185
+ * bindings, which would then fail as well.
186
+ */
187
+ async _onOwnChannel(model, operation, run) {
188
+ let channel;
189
+ try {
190
+ channel = await model.createChannel();
191
+ channel.on("error", (err) => {
192
+ this.log.debug({ err }, "%s %s->%s failed: %s", operation, this._source.name, this._destination.name, err.message);
193
+ });
194
+ await run(channel);
195
+ }
196
+ finally {
197
+ channel?.close().catch(() => { });
198
+ }
199
+ }
200
+ async _bind(model, generation, attempt) {
201
+ const destination = this._destination;
202
+ const source = this._source;
203
+ try {
204
+ // both are initialized on this generation already, unless they were declared after it started. A source on
205
+ // another connection is only waited for, as in 3.x: initializing it here would move it onto this connection
206
+ await Promise.all([
207
+ destination._initialize(model, generation),
208
+ this._isCrossConnection ? source.initialized : source._initialize(model, generation),
209
+ ]);
210
+ if (attempt !== this._attempt) {
211
+ return;
212
+ }
213
+ if (this._deleting !== undefined) {
214
+ throw new Error(`Binding ${this._id} was deleted`);
215
+ }
216
+ await this._create(model);
217
+ if (attempt !== this._attempt) {
218
+ return;
92
219
  }
93
- else {
94
- const exchange = this._destination;
95
- exchange.initialized.then(() => {
96
- exchange._channel.unbindExchange(this._destination.name, this._source.name, this.pattern, this.args, (err, _ok) => {
97
- /* istanbul ignore if */
98
- if (err) {
99
- reject(err);
100
- }
101
- else {
102
- delete this._destination.connection._bindings[Binding.id(this._destination, this._source, this.pattern)];
103
- resolve(null);
104
- }
105
- });
106
- });
220
+ if (destination.connection._isModelClosed(model)) {
221
+ throw new Error("Connection closed while the binding was created");
107
222
  }
108
- });
223
+ this._deferred.resolve(this);
224
+ }
225
+ catch (err) {
226
+ if (attempt !== this._attempt) {
227
+ return;
228
+ }
229
+ if (!this._isDeclared) {
230
+ // deleted, replaced or removed together with a failed end: nothing creates it again
231
+ this._rejectPending(err);
232
+ throw err;
233
+ }
234
+ if (destination.connection._isModelClosed(model)) {
235
+ // the next connect initializes it again, until then initialized stays pending
236
+ this.log.debug({ err }, "Connection lost while binding %s->%s.", source.name, destination.name);
237
+ throw err;
238
+ }
239
+ this.log.error({ err }, "Failed to create %s binding (%s->%s)", destination instanceof Queue ? "queue" : "exchange", source.name, destination.name);
240
+ delete destination.connection._bindings[Binding.id(destination, source, this.pattern)];
241
+ this._deferred.reject(err);
242
+ destination.connection._onEntityFailed(this, err);
243
+ throw err;
244
+ }
245
+ }
246
+ /**
247
+ * Deletes this binding of either a queue or an exchange. It is no longer declared from then on, so nothing creates it
248
+ * again, and an {@link initialized} that is still pending rejects. The unbind runs once the destination is
249
+ * initialized, on a short-lived channel. Deleting it again returns the same promise, also after a failure. A binding
250
+ * that was already replaced by binding the same pair again is only settled: the broker binding is the newer one's.
251
+ */
252
+ delete() {
253
+ this._deleting ??= this._delete();
254
+ return this._deleting;
255
+ }
256
+ async _delete() {
257
+ const destination = this._destination;
258
+ const connection = destination.connection;
259
+ const declared = this._isDeclared;
260
+ if (declared) {
261
+ delete connection._bindings[this._id];
262
+ }
263
+ this._rejectPending(new Error(`Binding ${this._id} was deleted`));
264
+ if (!declared) {
265
+ // replaced by binding the same pair again, or removed with a failed end: the broker binding, if any, belongs to
266
+ // the binding that replaced it, so unbinding it here would remove it from under that one
267
+ return;
268
+ }
269
+ await destination.initialized;
270
+ // a creation that is still in flight would create it again after the unbind
271
+ await this._creating;
272
+ const model = connection._activeModel;
273
+ if (model === undefined) {
274
+ throw new Error(`Connection lost while binding ${this._id} was deleted`);
275
+ }
276
+ await this._onOwnChannel(model, "Unbind", (channel) => destination instanceof Queue
277
+ ? channel.unbindQueue(destination.name, this._source.name, this.pattern, this.args)
278
+ : channel.unbindExchange(destination.name, this._source.name, this.pattern, this.args));
109
279
  }
110
280
  }
111
- exports.Binding = Binding;
112
281
  //# sourceMappingURL=Binding.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Binding.js","sourceRoot":"","sources":["../src/Binding.ts"],"names":[],"mappings":";;;AAEA,yCAAsC;AAEtC,MAAa,OAAO;IACX,MAAM,CAAC,EAAE,CAAC,WAA6B,EAAE,MAAgB,EAAE,OAAgB;QAChF,OAAO,GAAG,OAAO,IAAI,EAAE,CAAC;QACxB,OAAO,CACL,GAAG;YACH,MAAM,CAAC,IAAI;YACX,KAAK;YACL,CAAC,WAAW,YAAY,aAAK,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,UAAU,CAAC;YACrD,GAAG;YACH,WAAW,CAAC,IAAI;YAChB,GAAG;YACH,OAAO,CACR,CAAC;IACJ,CAAC;IAEM,MAAM,CAAC,wBAAwB,CAAC,eAAiC;QACtE,MAAM,UAAU,GAAG,eAAe,CAAC,UAAU,CAAC;QAC9C,MAAM,QAAQ,GAAoB,EAAE,CAAC;QACrC,KAAK,MAAM,SAAS,IAAI,UAAU,CAAC,SAAS,EAAE,CAAC;YAC7C,MAAM,OAAO,GAAY,UAAU,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;YACzD,IAAI,OAAO,CAAC,OAAO,KAAK,eAAe,IAAI,OAAO,CAAC,YAAY,KAAK,eAAe,EAAE,CAAC;gBACpF,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;YAClC,CAAC;QACH,CAAC;QACD,OAAO,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC/B,CAAC;IAOD,YAAY,WAA6B,EAAE,MAAgB,EAAU,UAAU,EAAE,EAAU,OAAY,EAAE;QAApC,YAAO,GAAP,OAAO,CAAK;QAAU,SAAI,GAAJ,IAAI,CAAU;QACvG,IAAI,CAAC,GAAG,GAAG,WAAW,CAAC,UAAU,CAAC,aAAa,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QAClE,IAAI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AmqpLib from "amqplib/callback_api";
2
- import { EventEmitter } from "events";
3
- import { Binding } from "../Binding";
4
- import { DeclarationOptions as ExchangeDeclarationOptions } from "../Exchange/DeclarationOptions";
5
- import { Exchange } from "../Exchange/Exchange";
6
- import { ExchangeType } from "../Exchange/ExchangeType";
7
- import { LoggerFactory } from "../LoggerFactory";
8
- import { DeclarationOptions as QueueDeclarationOptions } from "../Queue/DeclarationOptions";
9
- import { Queue } from "../Queue/Queue";
10
- import { ConnectionMetrics } from "./ConnectionMetrics";
11
- import { ReconnectStrategy } from "./ReconnectStrategy";
12
- import { Topology } from "./Topology";
1
+ import { type ChannelModel, type SocketOptions } from "amqplib";
2
+ import { EventEmitter } from "node:events";
3
+ import { DeclarationOptions as ExchangeDeclarationOptions } from "../Exchange/DeclarationOptions.js";
4
+ import { Exchange } from "../Exchange/Exchange.js";
5
+ import { ExchangeType } from "../Exchange/ExchangeType.js";
6
+ import { LoggerFactory } from "../LoggerFactory.js";
7
+ import { DeclarationOptions as QueueDeclarationOptions } from "../Queue/DeclarationOptions.js";
8
+ import { Queue } from "../Queue/Queue.js";
9
+ import { ConnectionMetrics } from "./ConnectionMetrics.js";
10
+ import { RecoveryOptions } from "./RecoveryOptions.js";
11
+ import { Topology } from "./Topology.js";
13
12
  export declare class Connection extends EventEmitter {
14
13
  loggerFactory?: LoggerFactory;
14
+ /**
15
+ * Resolves once the connection is established and the declared topology was set up. It is replaced by a pending
16
+ * promise when the connection is lost and resolves again after the next successful reconnect. It rejects when
17
+ * recovery gives up or the connection is closed before it was established.
18
+ *
19
+ * It only reflects the connection: an exchange, queue, binding or consumer that fails on its own does not keep it
20
+ * from resolving. Use {@link completeConfiguration} to wait for the topology.
21
+ */
15
22
  initialized: Promise<void>;
16
- connection: AmqpLib.Connection;
17
23
  isConnected: boolean;
18
- _exchanges: {
19
- [id: string]: Exchange;
20
- };
21
- _queues: {
22
- [id: string]: Queue;
23
- };
24
- _bindings: {
25
- [id: string]: Binding;
26
- };
27
- private url;
28
- private socketOptions;
29
- private reconnectStrategy;
30
- private connectedBefore;
31
- private _retry;
32
- private _rebuilding;
24
+ private _deferred;
25
+ private _recovering;
26
+ /** Counter for connect attempts that reach `setup`; each of them gets its own generation. */
27
+ private _lastGeneration;
28
+ /** The model `setup` is currently running for, and its generation. */
29
+ private _setupModel;
30
+ private _setupGeneration;
31
+ private _closedModels;
32
+ private _connectedBefore;
33
33
  private _isClosing;
34
+ private _closing;
35
+ /** Why recovery is over, set by {@link close} or when recovery gave up. Nothing is initialized after that. */
36
+ private _stopError;
37
+ /** Why exchanges, queues and bindings failed on their own, until the same one is declared again. */
38
+ private _failures;
34
39
  private log;
35
40
  private _sentMessagesCounter;
36
41
  private _receivedMessagesCounter;
37
42
  /**
38
43
  *
39
44
  * @param url The url to RabbitMQ
40
- * @param socketOptions Socket options are passed to {@link AmqpLib.connect}.
41
- * @param reconnectStrategy Options specifying the reconnect strategy.
45
+ * @param socketOptions Socket options are passed to amqplib's `connect`.
46
+ * @param recovery Options for the automatic reconnect, passed to amqplib's connection recovery. By default it retries
47
+ * forever with exponential backoff.
42
48
  * @param loggerFactory A factory function that returns a logger.
43
49
  */
44
- constructor(url?: string, socketOptions?: any, reconnectStrategy?: ReconnectStrategy, loggerFactory?: LoggerFactory);
45
- tryToConnect(thisConnection: Connection, retry: number, callback: (err: any) => void): void;
46
- _rebuildAll(err: Error): Promise<void>;
50
+ constructor(url?: string, socketOptions?: SocketOptions, recovery?: RecoveryOptions, loggerFactory?: LoggerFactory);
47
51
  close(): Promise<void>;
52
+ private static _failureKey;
53
+ private _close;
54
+ /**
55
+ * Recovery is over, because of {@link close} or because it gave up: rejects every promise that is still pending,
56
+ * the connection's and the entities', since nothing settles them any more.
57
+ */
58
+ private _stop;
59
+ /**
60
+ * Emits an event to the user's listeners. Most events are emitted from within amqplib's recovery, where a throwing
61
+ * listener would stop the reconnect from being scheduled, or from a promise chain, where it would be an unhandled
62
+ * rejection. So a listener's error is logged instead, and the listeners after it still get the event. The order is
63
+ * that of `emit`, and `once` listeners remove themselves as usual.
64
+ */
65
+ private _emitSafely;
66
+ private _listen;
67
+ /**
68
+ * Runs after every successful (re)connect, before amqplib installs the model: rebuilds the topology on fresh
69
+ * channels. It only throws when the model itself closed meanwhile, which makes amqplib schedule another reconnect.
70
+ */
71
+ private _setup;
72
+ /**
73
+ * Initializes every entity that is not initialized on the given generation yet: exchanges, then queues, then
74
+ * bindings, then queue consumers. Entity failures are handled by the entities themselves.
75
+ *
76
+ * A binding whose source exchange belongs to another connection waits for that connection, so it is not awaited:
77
+ * an outage of the other connection must not hold up this one's recovery.
78
+ */
79
+ private _declareEntities;
80
+ private _onConnect;
81
+ private _onDisconnect;
82
+ /** Recovery gave up: no further reconnect is attempted. */
83
+ private _giveUp;
84
+ /** Replaces a settled {@link initialized} with a pending one. */
85
+ private _invalidate;
48
86
  /**
49
- * Make sure the whole defined connection topology is configured. Goes through each exchange, queue and binding and
50
- * waits until all of them are initialized.
87
+ * Waits until the whole declared topology is initialized: every exchange, queue and binding, and the consumer of
88
+ * every queue with an activated consumer. Use it to gate the start of an application, since {@link initialized}
89
+ * only reflects the connection.
51
90
  *
52
- * @return A promise that fulfills after all defined exchanges, queues and bindings are initialized.
91
+ * It rejects when one of them failed on its own, at the first connect or later. A failed exchange, queue or binding
92
+ * counts until one with the same name is declared again (or {@link deleteConfiguration} is called), a refused
93
+ * consumer until it is registered on the next reconnect. While the connection is down it waits for the reconnect.
94
+ *
95
+ * @return A promise that fulfills after all defined exchanges, queues, bindings and consumers are initialized.
53
96
  */
54
97
  completeConfiguration(): Promise<any>;
55
98
  /**
56
- * Delete the whole defined connection topology:
57
- * return promise that fulfills after all defined exchanges, queues and bindings have been removed
99
+ * Deletes the whole defined topology in phases: first the bindings, then the queues together with their consumers,
100
+ * then the exchanges. Deleting a queue or an exchange deletes its bindings as well, so running the phases one after
101
+ * the other unbinds every binding only once. A phase that fails does not stop the next one.
102
+ *
103
+ * @return A promise that fulfills after all defined exchanges, queues and bindings have been removed, and rejects
104
+ * with the first failure otherwise.
58
105
  */
59
106
  deleteConfiguration(): Promise<any>;
60
107
  /**
@@ -92,17 +139,11 @@ export declare class Connection extends EventEmitter {
92
139
  */
93
140
  declareQueueAsync(name: string, options?: QueueDeclarationOptions): Promise<Queue>;
94
141
  declareTopology(topology: Topology): Promise<any>;
95
- get getConnection(): AmqpLib.Connection;
142
+ /** The current underlying amqplib model, `undefined` while disconnected. */
143
+ get getConnection(): ChannelModel | undefined;
96
144
  /**
97
145
  * Returns an object with metrics about the connection.
98
146
  * @returns An object containing metrics about the connection.
99
147
  */
100
148
  getMetrics(): ConnectionMetrics;
101
- private rebuildConnection;
102
- /**
103
- * Increments an internal counter.
104
- * @param counter The counter to increase.
105
- * @param value The increment, default is 1.
106
- */
107
- _increaseCounter(counter: "receivedMessages" | "sentMessages", value?: number): void;
108
149
  }