@zdavison/matador 2.0.3 → 2.0.4
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/matador.d.ts +2 -2
- package/dist/core/matador.d.ts.map +1 -1
- package/dist/core/matador.js +1 -0
- package/dist/index.cjs +44 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/pipeline/pipeline.d.ts +4 -1
- package/dist/pipeline/pipeline.d.ts.map +1 -1
- package/dist/pipeline/pipeline.js +16 -4
- package/dist/pipeline/pipeline.test.js +15 -1
- package/dist/topology/builder.d.ts.map +1 -1
- package/dist/topology/builder.js +2 -1
- package/dist/topology/builder.test.js +68 -0
- package/dist/topology/index.d.ts +2 -2
- package/dist/topology/index.d.ts.map +1 -1
- package/dist/topology/index.js +1 -1
- package/dist/topology/types.d.ts +53 -1
- package/dist/topology/types.d.ts.map +1 -1
- package/dist/topology/types.js +10 -0
- package/dist/transport/rabbitmq/rabbitmq-transport.d.ts.map +1 -1
- package/dist/transport/rabbitmq/rabbitmq-transport.js +30 -22
- package/dist/transport/rabbitmq/rabbitmq-transport.test.js +1 -1
- package/dist/types/dispatcher.d.ts +14 -0
- package/dist/types/dispatcher.d.ts.map +1 -0
- package/dist/types/dispatcher.js +1 -0
- package/dist/types/index.d.ts +2 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/subscriber.d.ts +20 -4
- package/dist/types/subscriber.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/core/matador.ts +3 -1
- package/src/index.ts +9 -0
- package/src/pipeline/pipeline.test.ts +24 -2
- package/src/pipeline/pipeline.ts +28 -6
- package/src/topology/builder.test.ts +90 -0
- package/src/topology/builder.ts +2 -1
- package/src/topology/index.ts +4 -0
- package/src/topology/types.ts +75 -1
- package/src/transport/rabbitmq/rabbitmq-transport.test.ts +1 -1
- package/src/transport/rabbitmq/rabbitmq-transport.ts +33 -25
- package/src/types/dispatcher.ts +18 -0
- package/src/types/index.ts +4 -0
- package/src/types/subscriber.ts +22 -3
- package/test/e2e/rabbitmq-transport.e2e.test.ts +287 -0
- package/tsconfig.tsbuildinfo +1 -1
package/dist/core/matador.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import type { RetryPolicy } from '../retry/index.js';
|
|
|
5
5
|
import type { MatadorSchema } from '../schema/index.js';
|
|
6
6
|
import type { Topology } from '../topology/index.js';
|
|
7
7
|
import type { Transport } from '../transport/index.js';
|
|
8
|
-
import type { AnySubscriber, Event, EventClass, EventOptions } from '../types/index.js';
|
|
8
|
+
import type { AnySubscriber, Dispatcher, Event, EventClass, EventOptions } from '../types/index.js';
|
|
9
9
|
import type { SendResult } from './fanout.js';
|
|
10
10
|
import type { HandlersState, ShutdownConfig } from './shutdown.js';
|
|
11
11
|
/**
|
|
@@ -44,7 +44,7 @@ export interface MatadorConfig {
|
|
|
44
44
|
* - Fanout: Event sending
|
|
45
45
|
* - Shutdown: Graceful termination
|
|
46
46
|
*/
|
|
47
|
-
export declare class Matador {
|
|
47
|
+
export declare class Matador implements Dispatcher {
|
|
48
48
|
private readonly transport;
|
|
49
49
|
private readonly topology;
|
|
50
50
|
private readonly schema;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"matador.d.ts","sourceRoot":"","sources":["../../src/core/matador.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAO/C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAGtD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAExD,OAAO,KAAK,EAAE,Q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,IAAI,OAAO,CAAC,IAAI,CAAC;IAS/B;;OAEG;IACH,WAAW,IAAI,OAAO;YAIR,aAAa;CAM5B"}
|
package/dist/core/matador.js
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -330,6 +330,12 @@ function getDeadLetterQueueName(namespace, queueName, dlqType) {
|
|
|
330
330
|
function getRetryQueueName(namespace, queueName) {
|
|
331
331
|
return `${namespace}.${queueName}.retry`;
|
|
332
332
|
}
|
|
333
|
+
function resolveQueueName(namespace, queueDef) {
|
|
334
|
+
if (queueDef.exact) {
|
|
335
|
+
return queueDef.name;
|
|
336
|
+
}
|
|
337
|
+
return `${namespace}.${queueDef.name}`;
|
|
338
|
+
}
|
|
333
339
|
|
|
334
340
|
// src/topology/builder.ts
|
|
335
341
|
function isQueueDefinition(arg) {
|
|
@@ -440,7 +446,7 @@ var TopologyBuilder = class _TopologyBuilder {
|
|
|
440
446
|
for (const queue of this.queues) {
|
|
441
447
|
if (!queue.name || queue.name.trim() === "") {
|
|
442
448
|
issues.push("Queue name cannot be empty");
|
|
443
|
-
} else if (!/^[a-zA-Z][a-zA-Z0-9_-]*$/.test(queue.name)) {
|
|
449
|
+
} else if (!queue.exact && !/^[a-zA-Z][a-zA-Z0-9_-]*$/.test(queue.name)) {
|
|
444
450
|
issues.push(
|
|
445
451
|
`Queue name "${queue.name}" must start with a letter and contain only alphanumeric characters, underscores, and hyphens`
|
|
446
452
|
);
|
|
@@ -1406,6 +1412,7 @@ var ProcessingPipeline = class {
|
|
|
1406
1412
|
retryPolicy;
|
|
1407
1413
|
hooks;
|
|
1408
1414
|
checkpointStore;
|
|
1415
|
+
dispatcher;
|
|
1409
1416
|
constructor(config) {
|
|
1410
1417
|
this.transport = config.transport;
|
|
1411
1418
|
this.schema = config.schema;
|
|
@@ -1413,6 +1420,7 @@ var ProcessingPipeline = class {
|
|
|
1413
1420
|
this.retryPolicy = config.retryPolicy;
|
|
1414
1421
|
this.hooks = config.hooks;
|
|
1415
1422
|
this.checkpointStore = config.checkpointStore ?? new NoOpCheckpointStore();
|
|
1423
|
+
this.dispatcher = config.dispatcher;
|
|
1416
1424
|
}
|
|
1417
1425
|
/**
|
|
1418
1426
|
* Processes a raw message from the transport.
|
|
@@ -1499,15 +1507,23 @@ var ProcessingPipeline = class {
|
|
|
1499
1507
|
}
|
|
1500
1508
|
});
|
|
1501
1509
|
}
|
|
1510
|
+
const callbackContext = { matador: this.dispatcher };
|
|
1502
1511
|
await this.hooks.onWorkerWrap(envelope, subscriberDef, async () => {
|
|
1503
1512
|
await this.hooks.onWorkerBeforeProcess(envelope, subscriberDef);
|
|
1504
1513
|
try {
|
|
1505
1514
|
if (isResumable && context) {
|
|
1506
1515
|
const resumableCallback = subscriber.callback;
|
|
1507
|
-
|
|
1516
|
+
const fullContext = {
|
|
1517
|
+
io: context.io.bind(context),
|
|
1518
|
+
all: context.all.bind(context),
|
|
1519
|
+
attempt: context.attempt,
|
|
1520
|
+
isRetry: context.isRetry,
|
|
1521
|
+
matador: this.dispatcher
|
|
1522
|
+
};
|
|
1523
|
+
result = await resumableCallback(envelope, fullContext);
|
|
1508
1524
|
} else {
|
|
1509
1525
|
const standardCallback = subscriber.callback;
|
|
1510
|
-
result = await standardCallback(envelope);
|
|
1526
|
+
result = await standardCallback(envelope, callbackContext);
|
|
1511
1527
|
}
|
|
1512
1528
|
} catch (e) {
|
|
1513
1529
|
error = e instanceof Error ? e : new Error(String(e));
|
|
@@ -1940,7 +1956,8 @@ var Matador = class {
|
|
|
1940
1956
|
codec: this.codec,
|
|
1941
1957
|
retryPolicy: this.retryPolicy,
|
|
1942
1958
|
hooks: this.hooks,
|
|
1943
|
-
checkpointStore: config.checkpointStore
|
|
1959
|
+
checkpointStore: config.checkpointStore,
|
|
1960
|
+
dispatcher: this
|
|
1944
1961
|
});
|
|
1945
1962
|
const defaultQueue = this.topology.queues[0]?.name ?? "default";
|
|
1946
1963
|
this.fanout = new FanoutEngine({
|
|
@@ -2986,24 +3003,29 @@ var RabbitMQTransport = class {
|
|
|
2986
3003
|
}
|
|
2987
3004
|
async assertWorkQueue(channel, topology, queueDef) {
|
|
2988
3005
|
const queueName = queueDef.exact ? queueDef.name : `${topology.namespace}.${queueDef.name}`;
|
|
2989
|
-
const
|
|
2990
|
-
|
|
2991
|
-
|
|
2992
|
-
}
|
|
2993
|
-
|
|
2994
|
-
|
|
2995
|
-
|
|
2996
|
-
|
|
2997
|
-
|
|
2998
|
-
|
|
2999
|
-
|
|
3000
|
-
|
|
3001
|
-
|
|
3002
|
-
|
|
3003
|
-
|
|
3004
|
-
|
|
3006
|
+
const rabbitmqOptions = queueDef.transport?.rabbitmq?.options;
|
|
3007
|
+
if (rabbitmqOptions) {
|
|
3008
|
+
await channel.assertQueue(queueName, rabbitmqOptions);
|
|
3009
|
+
} else {
|
|
3010
|
+
const queueOptions = {
|
|
3011
|
+
durable: true,
|
|
3012
|
+
arguments: {}
|
|
3013
|
+
};
|
|
3014
|
+
if (this.config.quorumQueues && !queueDef.exact) {
|
|
3015
|
+
queueOptions.arguments["x-queue-type"] = "quorum";
|
|
3016
|
+
}
|
|
3017
|
+
const dlxExchange = this.getDLXExchangeName(topology.namespace);
|
|
3018
|
+
if (topology.deadLetter.unhandled.enabled || topology.deadLetter.undeliverable.enabled) {
|
|
3019
|
+
queueOptions.arguments["x-dead-letter-exchange"] = dlxExchange;
|
|
3020
|
+
}
|
|
3021
|
+
if (queueDef.priorities) {
|
|
3022
|
+
queueOptions.arguments["x-max-priority"] = 10;
|
|
3023
|
+
}
|
|
3024
|
+
if (queueDef.consumerTimeout) {
|
|
3025
|
+
queueOptions.arguments["x-consumer-timeout"] = queueDef.consumerTimeout;
|
|
3026
|
+
}
|
|
3027
|
+
await channel.assertQueue(queueName, queueOptions);
|
|
3005
3028
|
}
|
|
3006
|
-
await channel.assertQueue(queueName, queueOptions);
|
|
3007
3029
|
const mainExchange = this.getMainExchangeName(topology.namespace);
|
|
3008
3030
|
await channel.bindQueue(queueName, mainExchange, queueName);
|
|
3009
3031
|
if (this.delayedExchangeAvailable) {
|
|
@@ -3174,6 +3196,7 @@ exports.isSubscriber = isSubscriber;
|
|
|
3174
3196
|
exports.isSubscriberNotRegisteredError = isSubscriberNotRegisteredError;
|
|
3175
3197
|
exports.isSubscriberStub = isSubscriberStub;
|
|
3176
3198
|
exports.isTransportNotConnectedError = isTransportNotConnectedError;
|
|
3199
|
+
exports.resolveQueueName = resolveQueueName;
|
|
3177
3200
|
exports.supportsDelayedMessages = supportsDelayedMessages;
|
|
3178
3201
|
exports.supportsDeliveryMode = supportsDeliveryMode;
|
|
3179
3202
|
exports.validResult = validResult;
|