@zdavison/matador 4.0.2 → 4.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/dist/core/fanout.d.ts +51 -0
- package/dist/core/fanout.d.ts.map +1 -1
- package/dist/core/fanout.js +141 -28
- package/dist/core/fanout.test.js +533 -7
- package/dist/core/matador.d.ts +33 -0
- package/dist/core/matador.d.ts.map +1 -1
- package/dist/core/matador.js +5 -1
- package/dist/core/matador.test.js +242 -6
- package/dist/errors/index.d.ts +1 -1
- package/dist/errors/index.d.ts.map +1 -1
- package/dist/errors/index.js +2 -2
- package/dist/errors/matador-errors.d.ts +10 -8
- package/dist/errors/matador-errors.d.ts.map +1 -1
- package/dist/errors/matador-errors.js +18 -14
- package/dist/index.cjs +215 -82
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/transport/local/local-transport.d.ts +6 -0
- package/dist/transport/local/local-transport.d.ts.map +1 -1
- package/dist/transport/local/local-transport.js +35 -18
- package/dist/transport/local/local-transport.test.js +40 -4
- package/dist/transport/multi/multi-transport.d.ts.map +1 -1
- package/dist/transport/multi/multi-transport.js +3 -0
- package/dist/transport/multi/multi-transport.test.js +82 -0
- package/dist/transport/rabbitmq/rabbitmq-transport.d.ts.map +1 -1
- package/dist/transport/rabbitmq/rabbitmq-transport.js +31 -27
- package/dist/transport/transport.d.ts +6 -0
- package/dist/transport/transport.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -29,6 +29,12 @@ export declare class LocalTransport implements Transport {
|
|
|
29
29
|
*/
|
|
30
30
|
private scheduleDelayedMessage;
|
|
31
31
|
private enqueue;
|
|
32
|
+
/**
|
|
33
|
+
* Stores a message and delivers it to any active subscribers, without
|
|
34
|
+
* requiring one to be present. Dead-letter queues are meant to hold
|
|
35
|
+
* messages for later manual inspection, so they don't need a live consumer.
|
|
36
|
+
*/
|
|
37
|
+
private storeAndDeliver;
|
|
32
38
|
private deliverToSubscribers;
|
|
33
39
|
subscribe(queue: string, handler: MessageHandler, options?: SubscribeOptions): Promise<Subscription>;
|
|
34
40
|
complete(receipt: MessageReceipt): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"local-transport.d.ts","sourceRoot":"","sources":["../../../src/transport/local/local-transport.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"local-transport.d.ts","sourceRoot":"","sources":["../../../src/transport/local/local-transport.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,MAAM,EAAiB,MAAM,sBAAsB,CAAC;AAClE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAExD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAChE,OAAO,KAAK,EACV,cAAc,EACd,cAAc,EACd,WAAW,EACX,gBAAgB,EAChB,YAAY,EACZ,SAAS,EACV,MAAM,iBAAiB,CAAC;AAuCzB;;;GAGG;AACH,qBAAa,cAAe,YAAW,SAAS;IAC9C,QAAQ,CAAC,IAAI,WAAW;IACxB,QAAQ,CAAC,YAAY,wBAAqB;IAE1C,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAiD;IACxE,OAAO,CAAC,QAAQ,CAAC,aAAa,CAA2C;IACzE,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAwB;IAC1D,OAAO,CAAC,QAAQ,CAAC,aAAa,CAA4C;IAC1E,OAAO,CAAC,gBAAgB,CAAK;IAC7B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;gBAEpB,MAAM,CAAC,EAAE,MAAM;IAIrB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAIxB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAiBjC,WAAW,IAAI,OAAO;IAIhB,aAAa,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IAsBhD,IAAI,CACR,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,QAAQ,EAClB,OAAO,CAAC,EAAE,WAAW,GACpB,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IAe7B;;;OAGG;IACH,OAAO,CAAC,sBAAsB;YAkBhB,OAAO;IASrB;;;;OAIG;YACW,eAAe;YAkBf,oBAAoB;IA8B5B,SAAS,CACb,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,cAAc,EACvB,OAAO,GAAE,gBAAqB,GAC7B,OAAO,CAAC,YAAY,CAAC;IA0ClB,QAAQ,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IAWhD,gBAAgB,CACpB,OAAO,EAAE,cAAc,EACvB,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,IAAI,CAAC;IAQhB;;OAEG;IACH,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAInC;;OAEG;IACH,YAAY,IAAI,SAAS,cAAc,EAAE;IAIzC;;OAEG;IACH,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,QAAQ,EAAE;IAMtD;;OAEG;IACH,KAAK,IAAI,IAAI;IAYb;;;OAGG;IACG,UAAU,CACd,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC;QAAE,QAAQ,EAAE,QAAQ,CAAC;QAAC,OAAO,EAAE,cAAc,CAAA;KAAE,GAAG,IAAI,CAAC;IAmBlE,OAAO,CAAC,gBAAgB;CAQzB"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TransportNotConnectedError } from '../../errors/index.js';
|
|
1
|
+
import { LocalTransportNoActiveSubscriberError, TransportNotConnectedError, } from '../../errors/index.js';
|
|
2
2
|
import { consoleLogger } from '../../hooks/index.js';
|
|
3
3
|
import { resolveQueueName } from '../../topology/types.js';
|
|
4
4
|
/**
|
|
@@ -13,6 +13,11 @@ const localCapabilities = {
|
|
|
13
13
|
ordering: 'queue',
|
|
14
14
|
priorities: false,
|
|
15
15
|
};
|
|
16
|
+
/**
|
|
17
|
+
* Maximum number of completed message receipts to retain.
|
|
18
|
+
* Oldest receipts are dropped once this limit is exceeded
|
|
19
|
+
*/
|
|
20
|
+
const MAX_COMPLETED_MESSAGES = 1000;
|
|
16
21
|
/**
|
|
17
22
|
* Local in-memory transport for testing and fallback.
|
|
18
23
|
* Messages are stored in memory and delivered synchronously.
|
|
@@ -61,7 +66,7 @@ export class LocalTransport {
|
|
|
61
66
|
for (const queueDef of topology.queues) {
|
|
62
67
|
const queueName = resolveQueueName(topology.namespace, queueDef, topology.naming, topology.prefix);
|
|
63
68
|
if (!this.queues.has(queueName)) {
|
|
64
|
-
this.queues.set(queueName,
|
|
69
|
+
this.queues.set(queueName, new Map());
|
|
65
70
|
}
|
|
66
71
|
}
|
|
67
72
|
}
|
|
@@ -92,6 +97,18 @@ export class LocalTransport {
|
|
|
92
97
|
this.delayedTimers.add(timer);
|
|
93
98
|
}
|
|
94
99
|
async enqueue(queue, envelope) {
|
|
100
|
+
const subs = this.subscriptions.get(queue);
|
|
101
|
+
if (!subs || subs.length === 0) {
|
|
102
|
+
throw new LocalTransportNoActiveSubscriberError(queue);
|
|
103
|
+
}
|
|
104
|
+
await this.storeAndDeliver(queue, envelope);
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Stores a message and delivers it to any active subscribers, without
|
|
108
|
+
* requiring one to be present. Dead-letter queues are meant to hold
|
|
109
|
+
* messages for later manual inspection, so they don't need a live consumer.
|
|
110
|
+
*/
|
|
111
|
+
async storeAndDeliver(queue, envelope) {
|
|
95
112
|
const messages = this.getOrCreateQueue(queue);
|
|
96
113
|
const messageId = `${++this.messageIdCounter}`;
|
|
97
114
|
const queuedMessage = {
|
|
@@ -99,16 +116,11 @@ export class LocalTransport {
|
|
|
99
116
|
id: messageId,
|
|
100
117
|
completed: false,
|
|
101
118
|
};
|
|
102
|
-
messages.
|
|
103
|
-
// Deliver to any active subscriptions
|
|
119
|
+
messages.set(messageId, queuedMessage);
|
|
104
120
|
await this.deliverToSubscribers(queue, queuedMessage);
|
|
105
121
|
}
|
|
106
122
|
async deliverToSubscribers(queue, message) {
|
|
107
|
-
const subs = this.subscriptions.get(queue);
|
|
108
|
-
if (!subs) {
|
|
109
|
-
this.logger.warn(`[Matador][LocalTransport] 🟡 No subscriptions found for queue '${queue}', message will be lost.`);
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
123
|
+
const subs = this.subscriptions.get(queue) ?? [];
|
|
112
124
|
for (const sub of subs) {
|
|
113
125
|
if (!sub.active || message.completed)
|
|
114
126
|
continue;
|
|
@@ -142,7 +154,7 @@ export class LocalTransport {
|
|
|
142
154
|
subs.push(subscription);
|
|
143
155
|
this.subscriptions.set(queue, subs);
|
|
144
156
|
// Deliver any pending messages
|
|
145
|
-
const messages = this.queues.get(queue) ?? [];
|
|
157
|
+
const messages = this.queues.get(queue)?.values() ?? [];
|
|
146
158
|
for (const message of messages) {
|
|
147
159
|
if (message.completed)
|
|
148
160
|
continue;
|
|
@@ -159,6 +171,10 @@ export class LocalTransport {
|
|
|
159
171
|
this.subscriptions.delete(queue);
|
|
160
172
|
}
|
|
161
173
|
},
|
|
174
|
+
// No-op: LocalTransport is only ever fed from within the process
|
|
175
|
+
// So, when shutting down, it needs to continue and handle new messages until the end
|
|
176
|
+
// As, an ongoing message (before shutdown) could create new (local) messages
|
|
177
|
+
pauseForShutdown: async () => { },
|
|
162
178
|
get isActive() {
|
|
163
179
|
return subscription.active;
|
|
164
180
|
},
|
|
@@ -168,10 +184,14 @@ export class LocalTransport {
|
|
|
168
184
|
const message = receipt.handle;
|
|
169
185
|
message.completed = true;
|
|
170
186
|
this.completedMessages.push(receipt);
|
|
187
|
+
if (this.completedMessages.length > MAX_COMPLETED_MESSAGES) {
|
|
188
|
+
this.completedMessages.shift();
|
|
189
|
+
}
|
|
190
|
+
this.queues.get(receipt.sourceQueue)?.delete(message.id);
|
|
171
191
|
}
|
|
172
192
|
async sendToDeadLetter(receipt, dlqName, envelope, _reason) {
|
|
173
193
|
const dlqQueueName = `${receipt.sourceQueue}.${dlqName}`;
|
|
174
|
-
await this.
|
|
194
|
+
await this.storeAndDeliver(dlqQueueName, envelope);
|
|
175
195
|
await this.complete(receipt);
|
|
176
196
|
}
|
|
177
197
|
// Test helpers
|
|
@@ -179,10 +199,7 @@ export class LocalTransport {
|
|
|
179
199
|
* Gets the current size of a queue.
|
|
180
200
|
*/
|
|
181
201
|
getQueueSize(queue) {
|
|
182
|
-
|
|
183
|
-
if (!messages)
|
|
184
|
-
return 0;
|
|
185
|
-
return messages.filter((m) => !m.completed).length;
|
|
202
|
+
return this.queues.get(queue)?.size ?? 0;
|
|
186
203
|
}
|
|
187
204
|
/**
|
|
188
205
|
* Gets all completed message receipts.
|
|
@@ -197,7 +214,7 @@ export class LocalTransport {
|
|
|
197
214
|
const messages = this.queues.get(queue);
|
|
198
215
|
if (!messages)
|
|
199
216
|
return [];
|
|
200
|
-
return messages.
|
|
217
|
+
return Array.from(messages.values()).map((m) => m.envelope);
|
|
201
218
|
}
|
|
202
219
|
/**
|
|
203
220
|
* Clears all state (for test isolation).
|
|
@@ -220,7 +237,7 @@ export class LocalTransport {
|
|
|
220
237
|
const messages = this.queues.get(queue);
|
|
221
238
|
if (!messages)
|
|
222
239
|
return null;
|
|
223
|
-
const pending = messages.
|
|
240
|
+
const pending = messages.values().next().value;
|
|
224
241
|
if (!pending)
|
|
225
242
|
return null;
|
|
226
243
|
const receipt = {
|
|
@@ -236,7 +253,7 @@ export class LocalTransport {
|
|
|
236
253
|
getOrCreateQueue(queue) {
|
|
237
254
|
let messages = this.queues.get(queue);
|
|
238
255
|
if (!messages) {
|
|
239
|
-
messages =
|
|
256
|
+
messages = new Map();
|
|
240
257
|
this.queues.set(queue, messages);
|
|
241
258
|
}
|
|
242
259
|
return messages;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { beforeEach, describe, expect, it } from 'bun:test';
|
|
2
|
+
import { LocalTransportNoActiveSubscriberError } from '../../errors/index.js';
|
|
2
3
|
import { createEnvelope } from '../../types/index.js';
|
|
3
4
|
import { LocalTransport } from './local-transport.js';
|
|
4
5
|
describe('LocalTransport', () => {
|
|
@@ -31,12 +32,19 @@ describe('LocalTransport', () => {
|
|
|
31
32
|
describe('send and receive', () => {
|
|
32
33
|
beforeEach(async () => {
|
|
33
34
|
await transport.connect();
|
|
35
|
+
// A no-op subscriber makes 'test-queue' deliverable; LocalTransport now
|
|
36
|
+
// rejects sends to queues with no active subscriber in this process.
|
|
37
|
+
await transport.subscribe('test-queue', async () => { });
|
|
34
38
|
});
|
|
35
39
|
it('should throw when sending while disconnected', async () => {
|
|
36
40
|
await transport.disconnect();
|
|
37
41
|
const envelope = createTestEnvelope();
|
|
38
42
|
await expect(transport.send('test-queue', envelope)).rejects.toThrow('is not connected');
|
|
39
43
|
});
|
|
44
|
+
it('should throw when sending to a queue with no active subscriber', async () => {
|
|
45
|
+
const envelope = createTestEnvelope();
|
|
46
|
+
await expect(transport.send('unsubscribed-queue', envelope)).rejects.toThrow(LocalTransportNoActiveSubscriberError);
|
|
47
|
+
});
|
|
40
48
|
it('should send and receive a message', async () => {
|
|
41
49
|
const envelope = createTestEnvelope();
|
|
42
50
|
await transport.send('test-queue', envelope);
|
|
@@ -66,6 +74,24 @@ describe('LocalTransport', () => {
|
|
|
66
74
|
const received = await transport.receiveOne('empty-queue');
|
|
67
75
|
expect(received).toBeNull();
|
|
68
76
|
});
|
|
77
|
+
it('should preserve FIFO order of pending messages', async () => {
|
|
78
|
+
const envelopes = [0, 1, 2].map((seq) => createEnvelope({
|
|
79
|
+
eventKey: 'test.event',
|
|
80
|
+
targetSubscriber: 'test-subscriber',
|
|
81
|
+
data: { seq },
|
|
82
|
+
importance: 'should-investigate',
|
|
83
|
+
}));
|
|
84
|
+
for (const envelope of envelopes) {
|
|
85
|
+
await transport.send('test-queue', envelope);
|
|
86
|
+
}
|
|
87
|
+
expect(transport.getPendingMessages('test-queue').map((e) => e.data)).toEqual([{ seq: 0 }, { seq: 1 }, { seq: 2 }]);
|
|
88
|
+
for (const envelope of envelopes) {
|
|
89
|
+
const received = await transport.receiveOne('test-queue');
|
|
90
|
+
expect(received?.envelope.id).toBe(envelope.id);
|
|
91
|
+
if (received)
|
|
92
|
+
await transport.complete(received.receipt);
|
|
93
|
+
}
|
|
94
|
+
});
|
|
69
95
|
});
|
|
70
96
|
describe('subscriptions', () => {
|
|
71
97
|
beforeEach(async () => {
|
|
@@ -85,14 +111,21 @@ describe('LocalTransport', () => {
|
|
|
85
111
|
expect(receivedMessages).toHaveLength(1);
|
|
86
112
|
expect(receivedMessages[0].id).toBe(envelope.id);
|
|
87
113
|
});
|
|
88
|
-
it('should
|
|
114
|
+
it('should redeliver pending (uncompleted) messages to a newly attached subscriber', async () => {
|
|
115
|
+
const firstSubscriberMessages = [];
|
|
116
|
+
const firstSubscription = await transport.subscribe('test-queue', async (envelope) => {
|
|
117
|
+
firstSubscriberMessages.push(envelope);
|
|
118
|
+
});
|
|
89
119
|
const envelope = createTestEnvelope();
|
|
90
120
|
await transport.send('test-queue', envelope);
|
|
91
|
-
|
|
121
|
+
expect(firstSubscriberMessages).toHaveLength(1);
|
|
122
|
+
// First subscriber never completed the message before going away.
|
|
123
|
+
await firstSubscription.unsubscribe();
|
|
124
|
+
const secondSubscriberMessages = [];
|
|
92
125
|
await transport.subscribe('test-queue', async (env) => {
|
|
93
|
-
|
|
126
|
+
secondSubscriberMessages.push(env);
|
|
94
127
|
});
|
|
95
|
-
expect(
|
|
128
|
+
expect(secondSubscriberMessages).toHaveLength(1);
|
|
96
129
|
});
|
|
97
130
|
it('should stop delivering after unsubscribe', async () => {
|
|
98
131
|
const receivedMessages = [];
|
|
@@ -108,6 +141,7 @@ describe('LocalTransport', () => {
|
|
|
108
141
|
describe('dead letter queue', () => {
|
|
109
142
|
beforeEach(async () => {
|
|
110
143
|
await transport.connect();
|
|
144
|
+
await transport.subscribe('test-queue', async () => { });
|
|
111
145
|
});
|
|
112
146
|
it('should send messages to dead letter queue', async () => {
|
|
113
147
|
const envelope = createTestEnvelope();
|
|
@@ -145,6 +179,7 @@ describe('LocalTransport', () => {
|
|
|
145
179
|
describe('clear', () => {
|
|
146
180
|
it('should reset all state', async () => {
|
|
147
181
|
await transport.connect();
|
|
182
|
+
await transport.subscribe('test-queue', async () => { });
|
|
148
183
|
await transport.send('test-queue', createTestEnvelope());
|
|
149
184
|
const received = await transport.receiveOne('test-queue');
|
|
150
185
|
if (!received)
|
|
@@ -158,6 +193,7 @@ describe('LocalTransport', () => {
|
|
|
158
193
|
describe('delayed messages', () => {
|
|
159
194
|
beforeEach(async () => {
|
|
160
195
|
await transport.connect();
|
|
196
|
+
await transport.subscribe('test-queue', async () => { });
|
|
161
197
|
});
|
|
162
198
|
it('should return immediately and delay message delivery', async () => {
|
|
163
199
|
const envelope = createTestEnvelope();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"multi-transport.d.ts","sourceRoot":"","sources":["../../../src/transport/multi/multi-transport.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAC;AACrE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAChE,OAAO,KAAK,EACV,cAAc,EACd,cAAc,EACd,WAAW,EACX,gBAAgB,EAChB,YAAY,EACZ,SAAS,EACV,MAAM,iBAAiB,CAAC;AAgBzB;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC;;;;O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AC,SAAS,CAAC,MAAM,CAAC,CAAC;IA0C7B;;OAEG;YACW,eAAe;IAwB7B;;OAEG;IACH,OAAO,CAAC,iBAAiB;IASnB,SAAS,CACb,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,cAAc,EACvB,OAAO,CAAC,EAAE,gBAAgB,GACzB,OAAO,CAAC,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"multi-transport.d.ts","sourceRoot":"","sources":["../../../src/transport/multi/multi-transport.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAC;AACrE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAChE,OAAO,KAAK,EACV,cAAc,EACd,cAAc,EACd,WAAW,EACX,gBAAgB,EAChB,YAAY,EACZ,SAAS,EACV,MAAM,iBAAiB,CAAC;AAgBzB;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC;;;;OAIG;IACH,QAAQ,CAAC,UAAU,EAAE,SAAS,SAAS,EAAE,CAAC;IAE1C;;;;;;OAMG;IACH,QAAQ,CAAC,eAAe,CAAC,EAAE,OAAO,CAAC;CACpC;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC;;;;;;;;;;;;OAYG;IACH,QAAQ,CAAC,iBAAiB,CAAC,EAAE,MACzB,MAAM,GACN,SAAS,GACT,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;IAEhC;;;OAGG;IACH,QAAQ,CAAC,iBAAiB,CAAC,EAAE,CAAC,OAAO,EAAE,wBAAwB,KAAK,IAAI,CAAC;CAC1E;AAmBD;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,cAAe,YAAW,SAAS;IAC9C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB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Promise.all(subscriptions.map((s) => s.unsubscribe()));
|
|
186
186
|
},
|
|
187
|
+
pauseForShutdown: async () => {
|
|
188
|
+
await Promise.all(subscriptions.map((s) => (s.pauseForShutdown ?? s.unsubscribe)()));
|
|
189
|
+
},
|
|
187
190
|
get isActive() {
|
|
188
191
|
return subscriptions.some((s) => s.isActive);
|
|
189
192
|
},
|
|
@@ -83,6 +83,7 @@ describe('MultiTransport', () => {
|
|
|
83
83
|
describe('send - primary success', () => {
|
|
84
84
|
beforeEach(async () => {
|
|
85
85
|
await transport.connect();
|
|
86
|
+
await transport.subscribe('test-queue', async () => { });
|
|
86
87
|
});
|
|
87
88
|
it('should send to primary transport when it succeeds', async () => {
|
|
88
89
|
const envelope = createTestEnvelope();
|
|
@@ -102,6 +103,7 @@ describe('MultiTransport', () => {
|
|
|
102
103
|
describe('send - fallback', () => {
|
|
103
104
|
beforeEach(async () => {
|
|
104
105
|
await transport.connect();
|
|
106
|
+
await transport.subscribe('test-queue', async () => { });
|
|
105
107
|
});
|
|
106
108
|
it('should fallback when primary fails', async () => {
|
|
107
109
|
// Make primary fail
|
|
@@ -140,6 +142,7 @@ describe('MultiTransport', () => {
|
|
|
140
142
|
transports: [primary, secondary, third],
|
|
141
143
|
});
|
|
142
144
|
await multiTransport.connect();
|
|
145
|
+
await third.subscribe('test-queue', async () => { });
|
|
143
146
|
// Make primary and secondary fail
|
|
144
147
|
await primary.disconnect();
|
|
145
148
|
await secondary.disconnect();
|
|
@@ -200,10 +203,88 @@ describe('MultiTransport', () => {
|
|
|
200
203
|
expect(receivedMessages).toHaveLength(1);
|
|
201
204
|
expect(receivedMessages[0].id).toBe(envelope.id);
|
|
202
205
|
});
|
|
206
|
+
it('should leave sub-transports subscribed when pauseForShutdown is a no-op', async () => {
|
|
207
|
+
const receivedMessages = [];
|
|
208
|
+
const subscription = await transport.subscribe('test-queue', async (envelope) => {
|
|
209
|
+
receivedMessages.push(envelope);
|
|
210
|
+
});
|
|
211
|
+
// Both primary and secondary here are LocalTransport, whose
|
|
212
|
+
// pauseForShutdown is a no-op — pausing the aggregate must leave both
|
|
213
|
+
// underlying subscriptions untouched.
|
|
214
|
+
await subscription.pauseForShutdown?.();
|
|
215
|
+
await primary.send('test-queue', createTestEnvelope());
|
|
216
|
+
expect(receivedMessages).toHaveLength(1);
|
|
217
|
+
});
|
|
218
|
+
it('should call pauseForShutdown on sub-transports that implement it', async () => {
|
|
219
|
+
const externalPauseForShutdown = mock(async () => { });
|
|
220
|
+
const externalMock = {
|
|
221
|
+
name: 'rabbitmq',
|
|
222
|
+
capabilities: {
|
|
223
|
+
deliveryModes: ['at-least-once'],
|
|
224
|
+
delayedMessages: false,
|
|
225
|
+
deadLetterRouting: 'native',
|
|
226
|
+
attemptTracking: true,
|
|
227
|
+
concurrencyModel: 'prefetch',
|
|
228
|
+
ordering: 'none',
|
|
229
|
+
priorities: false,
|
|
230
|
+
},
|
|
231
|
+
isConnected: () => true,
|
|
232
|
+
connect: mock(async () => { }),
|
|
233
|
+
disconnect: mock(async () => { }),
|
|
234
|
+
send: mock(async () => 'rabbitmq'),
|
|
235
|
+
subscribe: mock(async () => ({
|
|
236
|
+
unsubscribe: mock(async () => { }),
|
|
237
|
+
pauseForShutdown: externalPauseForShutdown,
|
|
238
|
+
isActive: true,
|
|
239
|
+
})),
|
|
240
|
+
applyTopology: mock(async () => { }),
|
|
241
|
+
complete: mock(async () => { }),
|
|
242
|
+
};
|
|
243
|
+
const multiWithExternal = new MultiTransport({
|
|
244
|
+
transports: [externalMock, primary],
|
|
245
|
+
});
|
|
246
|
+
await multiWithExternal.connect();
|
|
247
|
+
const subscription = await multiWithExternal.subscribe('test-queue', async () => { });
|
|
248
|
+
await subscription.pauseForShutdown?.();
|
|
249
|
+
expect(externalPauseForShutdown).toHaveBeenCalledTimes(1);
|
|
250
|
+
});
|
|
251
|
+
it('should fall back to unsubscribe for sub-transports without pauseForShutdown', async () => {
|
|
252
|
+
const externalUnsubscribe = mock(async () => { });
|
|
253
|
+
const externalMock = {
|
|
254
|
+
name: 'rabbitmq',
|
|
255
|
+
capabilities: {
|
|
256
|
+
deliveryModes: ['at-least-once'],
|
|
257
|
+
delayedMessages: false,
|
|
258
|
+
deadLetterRouting: 'native',
|
|
259
|
+
attemptTracking: true,
|
|
260
|
+
concurrencyModel: 'prefetch',
|
|
261
|
+
ordering: 'none',
|
|
262
|
+
priorities: false,
|
|
263
|
+
},
|
|
264
|
+
isConnected: () => true,
|
|
265
|
+
connect: mock(async () => { }),
|
|
266
|
+
disconnect: mock(async () => { }),
|
|
267
|
+
send: mock(async () => 'rabbitmq'),
|
|
268
|
+
subscribe: mock(async () => ({
|
|
269
|
+
unsubscribe: externalUnsubscribe,
|
|
270
|
+
isActive: true,
|
|
271
|
+
})),
|
|
272
|
+
applyTopology: mock(async () => { }),
|
|
273
|
+
complete: mock(async () => { }),
|
|
274
|
+
};
|
|
275
|
+
const multiWithExternal = new MultiTransport({
|
|
276
|
+
transports: [externalMock, primary],
|
|
277
|
+
});
|
|
278
|
+
await multiWithExternal.connect();
|
|
279
|
+
const subscription = await multiWithExternal.subscribe('test-queue', async () => { });
|
|
280
|
+
await subscription.pauseForShutdown?.();
|
|
281
|
+
expect(externalUnsubscribe).toHaveBeenCalledTimes(1);
|
|
282
|
+
});
|
|
203
283
|
});
|
|
204
284
|
describe('complete', () => {
|
|
205
285
|
beforeEach(async () => {
|
|
206
286
|
await transport.connect();
|
|
287
|
+
await primary.subscribe('test-queue', async () => { });
|
|
207
288
|
});
|
|
208
289
|
it('should complete using primary transport', async () => {
|
|
209
290
|
await primary.send('test-queue', createTestEnvelope());
|
|
@@ -217,6 +298,7 @@ describe('MultiTransport', () => {
|
|
|
217
298
|
describe('sendToDeadLetter', () => {
|
|
218
299
|
beforeEach(async () => {
|
|
219
300
|
await transport.connect();
|
|
301
|
+
await primary.subscribe('test-queue', async () => { });
|
|
220
302
|
});
|
|
221
303
|
it('should send to dead letter using primary transport', async () => {
|
|
222
304
|
const envelope = createTestEnv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AAO,CAAC,IAAI,CAAC;IA4ChB;;;;;;;OAOG;IACH,OAAO,CAAC,cAAc;IAsCtB;;;;;OAKG;YACW,uBAAuB;YAqCvB,SAAS;YAiFT,YAAY;YA+CZ,oBAAoB;IAwElC,OAAO,CAAC,qBAAqB;YAgCf,eAAe;YAsCf,gBAAgB;YAoChB,sBAAsB;IAwCpC,OAAO,CAAC,mBAAmB;IAO3B,OAAO,CAAC,kBAAkB;IAO1B,OAAO,CAAC,sBAAsB;IAO9B,OAAO,CAAC,gBAAgB;IAiBxB;;;;OAIG;IACH,OAAO,CAAC,gBAAgB;CA0BzB"}
|
|
@@ -161,39 +161,43 @@ export class RabbitMQTransport {
|
|
|
161
161
|
};
|
|
162
162
|
this.subscriptionIntents.push(intent);
|
|
163
163
|
await this.activateIntent(intent);
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
164
|
+
const unsubscribe = async () => {
|
|
165
|
+
intent.active = false;
|
|
166
|
+
const idx = this.subscriptionIntents.indexOf(intent);
|
|
167
|
+
if (idx !== -1)
|
|
168
|
+
this.subscriptionIntents.splice(idx, 1);
|
|
169
|
+
const consumer = intent.currentConsumer;
|
|
170
|
+
if (consumer) {
|
|
171
|
+
consumer.active = false;
|
|
172
|
+
const queueChannel = this.queueChannels.get(queue);
|
|
173
|
+
if (queueChannel) {
|
|
174
|
+
try {
|
|
175
|
+
await queueChannel.channel.cancel(consumer.consumerTag);
|
|
176
|
+
}
|
|
177
|
+
catch {
|
|
178
|
+
// Channel may already be closed
|
|
179
|
+
}
|
|
180
|
+
const cIdx = queueChannel.consumers.indexOf(consumer);
|
|
181
|
+
if (cIdx !== -1)
|
|
182
|
+
queueChannel.consumers.splice(cIdx, 1);
|
|
183
|
+
if (queueChannel.consumers.length === 0) {
|
|
175
184
|
try {
|
|
176
|
-
await queueChannel.channel.
|
|
185
|
+
await queueChannel.channel.close();
|
|
177
186
|
}
|
|
178
187
|
catch {
|
|
179
|
-
//
|
|
180
|
-
}
|
|
181
|
-
const cIdx = queueChannel.consumers.indexOf(consumer);
|
|
182
|
-
if (cIdx !== -1)
|
|
183
|
-
queueChannel.consumers.splice(cIdx, 1);
|
|
184
|
-
if (queueChannel.consumers.length === 0) {
|
|
185
|
-
try {
|
|
186
|
-
await queueChannel.channel.close();
|
|
187
|
-
}
|
|
188
|
-
catch {
|
|
189
|
-
// Ignore
|
|
190
|
-
}
|
|
191
|
-
this.queueChannels.delete(queue);
|
|
188
|
+
// Ignore
|
|
192
189
|
}
|
|
190
|
+
this.queueChannels.delete(queue);
|
|
193
191
|
}
|
|
194
|
-
intent.currentConsumer = null;
|
|
195
192
|
}
|
|
196
|
-
|
|
193
|
+
intent.currentConsumer = null;
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
return {
|
|
197
|
+
unsubscribe,
|
|
198
|
+
// Messages on this transport comes from outside (RabbitMQ), so, when shutting down, we need to unsubscribe directly
|
|
199
|
+
// Otherwise, we could receive traffic forever, and an idle state would never be reached.
|
|
200
|
+
pauseForShutdown: unsubscribe,
|
|
197
201
|
get isActive() {
|
|
198
202
|
return intent.active;
|
|
199
203
|
},
|
|
@@ -96,6 +96,12 @@ export type MessageHandler = (envelope: Envelope, receipt: MessageReceipt) => Pr
|
|
|
96
96
|
export interface Subscription {
|
|
97
97
|
/** Cancels the subscription */
|
|
98
98
|
unsubscribe(): Promise<void>;
|
|
99
|
+
/**
|
|
100
|
+
* Stops delivering messages ahead of a graceful shutdown, without
|
|
101
|
+
* necessarily tearing down the subscription the way unsubscribe() does.
|
|
102
|
+
* Optional: only meaningful for externally-fed transports where traffic
|
|
103
|
+
*/
|
|
104
|
+
pauseForShutdown?(): Promise<void>;
|
|
99
105
|
/** Whether the subscription is currently active */
|
|
100
106
|
readonly isActive: boolean;
|
|
101
107
|
}
|
|
@@ -1 +1 @@
|
|
|
1
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