@zdavison/matador 2.0.7 → 2.0.9
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/package.json +3 -2
- package/src/hooks/safe-hooks.ts +0 -16
- package/src/hooks/types.ts +0 -7
- package/src/index.ts +1 -0
- package/src/types/event.ts +8 -14
- package/src/types/index.ts +3 -2
- package/dist/checkpoint/context.d.ts +0 -59
- package/dist/checkpoint/context.d.ts.map +0 -1
- package/dist/checkpoint/context.js +0 -140
- package/dist/checkpoint/context.test.d.ts +0 -2
- package/dist/checkpoint/context.test.d.ts.map +0 -1
- package/dist/checkpoint/context.test.js +0 -424
- package/dist/checkpoint/index.d.ts +0 -7
- package/dist/checkpoint/index.d.ts.map +0 -1
- package/dist/checkpoint/index.js +0 -6
- package/dist/checkpoint/stores/memory.d.ts +0 -29
- package/dist/checkpoint/stores/memory.d.ts.map +0 -1
- package/dist/checkpoint/stores/memory.js +0 -39
- package/dist/checkpoint/stores/noop.d.ts +0 -14
- package/dist/checkpoint/stores/noop.d.ts.map +0 -1
- package/dist/checkpoint/stores/noop.js +0 -18
- package/dist/checkpoint/stores/stores.test.d.ts +0 -2
- package/dist/checkpoint/stores/stores.test.d.ts.map +0 -1
- package/dist/checkpoint/stores/stores.test.js +0 -146
- package/dist/checkpoint/types.d.ts +0 -119
- package/dist/checkpoint/types.d.ts.map +0 -1
- package/dist/checkpoint/types.js +0 -1
- package/dist/codec/codec.d.ts +0 -29
- package/dist/codec/codec.d.ts.map +0 -1
- package/dist/codec/codec.js +0 -15
- package/dist/codec/header-aware-codec.d.ts +0 -36
- package/dist/codec/header-aware-codec.d.ts.map +0 -1
- package/dist/codec/header-aware-codec.js +0 -1
- package/dist/codec/index.d.ts +0 -6
- package/dist/codec/index.d.ts.map +0 -1
- package/dist/codec/index.js +0 -3
- package/dist/codec/json-codec.d.ts +0 -13
- package/dist/codec/json-codec.d.ts.map +0 -1
- package/dist/codec/json-codec.js +0 -64
- package/dist/codec/rabbitmq-codec.d.ts +0 -28
- package/dist/codec/rabbitmq-codec.d.ts.map +0 -1
- package/dist/codec/rabbitmq-codec.js +0 -242
- package/dist/codec/rabbitmq-codec.test.d.ts +0 -2
- package/dist/codec/rabbitmq-codec.test.d.ts.map +0 -1
- package/dist/codec/rabbitmq-codec.test.js +0 -433
- package/dist/core/fanout.d.ts +0 -59
- package/dist/core/fanout.d.ts.map +0 -1
- package/dist/core/fanout.js +0 -121
- package/dist/core/fanout.test.d.ts +0 -2
- package/dist/core/fanout.test.d.ts.map +0 -1
- package/dist/core/fanout.test.js +0 -1054
- package/dist/core/index.d.ts +0 -7
- package/dist/core/index.d.ts.map +0 -1
- package/dist/core/index.js +0 -3
- package/dist/core/matador.d.ts +0 -133
- package/dist/core/matador.d.ts.map +0 -1
- package/dist/core/matador.js +0 -228
- package/dist/core/matador.test.d.ts +0 -2
- package/dist/core/matador.test.d.ts.map +0 -1
- package/dist/core/matador.test.js +0 -446
- package/dist/core/shutdown.d.ts +0 -78
- package/dist/core/shutdown.d.ts.map +0 -1
- package/dist/core/shutdown.js +0 -111
- package/dist/core/shutdown.test.d.ts +0 -2
- package/dist/core/shutdown.test.d.ts.map +0 -1
- package/dist/core/shutdown.test.js +0 -524
- package/dist/errors/checkpoint-errors.d.ts +0 -30
- package/dist/errors/checkpoint-errors.d.ts.map +0 -1
- package/dist/errors/checkpoint-errors.js +0 -49
- package/dist/errors/has-description.d.ts +0 -18
- package/dist/errors/has-description.d.ts.map +0 -1
- package/dist/errors/has-description.js +0 -9
- package/dist/errors/index.d.ts +0 -6
- package/dist/errors/index.d.ts.map +0 -1
- package/dist/errors/index.js +0 -22
- package/dist/errors/matador-errors.d.ts +0 -183
- package/dist/errors/matador-errors.d.ts.map +0 -1
- package/dist/errors/matador-errors.js +0 -376
- package/dist/errors/retry-errors.d.ts +0 -102
- package/dist/errors/retry-errors.d.ts.map +0 -1
- package/dist/errors/retry-errors.js +0 -155
- package/dist/errors/retry-errors.test.d.ts +0 -2
- package/dist/errors/retry-errors.test.d.ts.map +0 -1
- package/dist/errors/retry-errors.test.js +0 -136
- package/dist/hooks/index.d.ts +0 -4
- package/dist/hooks/index.d.ts.map +0 -1
- package/dist/hooks/index.js +0 -2
- package/dist/hooks/safe-hooks.d.ts +0 -33
- package/dist/hooks/safe-hooks.d.ts.map +0 -1
- package/dist/hooks/safe-hooks.js +0 -132
- package/dist/hooks/types.d.ts +0 -176
- package/dist/hooks/types.d.ts.map +0 -1
- package/dist/hooks/types.js +0 -9
- package/dist/index.cjs +0 -3242
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -23
- package/dist/index.d.ts +0 -23
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -31
- package/dist/index.js.map +0 -1
- package/dist/pipeline/index.d.ts +0 -3
- package/dist/pipeline/index.d.ts.map +0 -1
- package/dist/pipeline/index.js +0 -1
- package/dist/pipeline/pipeline.d.ts +0 -63
- package/dist/pipeline/pipeline.d.ts.map +0 -1
- package/dist/pipeline/pipeline.js +0 -273
- package/dist/pipeline/pipeline.test.d.ts +0 -2
- package/dist/pipeline/pipeline.test.d.ts.map +0 -1
- package/dist/pipeline/pipeline.test.js +0 -1112
- package/dist/retry/index.d.ts +0 -4
- package/dist/retry/index.d.ts.map +0 -1
- package/dist/retry/index.js +0 -1
- package/dist/retry/policy.d.ts +0 -43
- package/dist/retry/policy.d.ts.map +0 -1
- package/dist/retry/policy.js +0 -1
- package/dist/retry/standard-policy.d.ts +0 -44
- package/dist/retry/standard-policy.d.ts.map +0 -1
- package/dist/retry/standard-policy.js +0 -102
- package/dist/retry/standard-policy.test.d.ts +0 -2
- package/dist/retry/standard-policy.test.d.ts.map +0 -1
- package/dist/retry/standard-policy.test.js +0 -196
- package/dist/schema/index.d.ts +0 -4
- package/dist/schema/index.d.ts.map +0 -1
- package/dist/schema/index.js +0 -2
- package/dist/schema/registry.d.ts +0 -63
- package/dist/schema/registry.d.ts.map +0 -1
- package/dist/schema/registry.js +0 -174
- package/dist/schema/registry.test.d.ts +0 -2
- package/dist/schema/registry.test.d.ts.map +0 -1
- package/dist/schema/registry.test.js +0 -278
- package/dist/schema/types.d.ts +0 -158
- package/dist/schema/types.d.ts.map +0 -1
- package/dist/schema/types.js +0 -74
- package/dist/schema/types.test.d.ts +0 -2
- package/dist/schema/types.test.d.ts.map +0 -1
- package/dist/schema/types.test.js +0 -242
- package/dist/topology/builder.d.ts +0 -80
- package/dist/topology/builder.d.ts.map +0 -1
- package/dist/topology/builder.js +0 -165
- package/dist/topology/builder.test.d.ts +0 -2
- package/dist/topology/builder.test.d.ts.map +0 -1
- package/dist/topology/builder.test.js +0 -360
- package/dist/topology/index.d.ts +0 -5
- package/dist/topology/index.d.ts.map +0 -1
- package/dist/topology/index.js +0 -2
- package/dist/topology/types.d.ts +0 -128
- package/dist/topology/types.d.ts.map +0 -1
- package/dist/topology/types.js +0 -28
- package/dist/transport/capabilities.d.ts +0 -66
- package/dist/transport/capabilities.d.ts.map +0 -1
- package/dist/transport/capabilities.js +0 -18
- package/dist/transport/connection-manager.d.ts +0 -95
- package/dist/transport/connection-manager.d.ts.map +0 -1
- package/dist/transport/connection-manager.js +0 -144
- package/dist/transport/index.d.ts +0 -11
- package/dist/transport/index.d.ts.map +0 -1
- package/dist/transport/index.js +0 -5
- package/dist/transport/local/local-transport.d.ts +0 -62
- package/dist/transport/local/local-transport.d.ts.map +0 -1
- package/dist/transport/local/local-transport.js +0 -241
- package/dist/transport/local/local-transport.test.d.ts +0 -2
- package/dist/transport/local/local-transport.test.d.ts.map +0 -1
- package/dist/transport/local/local-transport.test.js +0 -192
- package/dist/transport/multi/multi-transport.d.ts +0 -94
- package/dist/transport/multi/multi-transport.d.ts.map +0 -1
- package/dist/transport/multi/multi-transport.js +0 -184
- package/dist/transport/multi/multi-transport.test.d.ts +0 -2
- package/dist/transport/multi/multi-transport.test.d.ts.map +0 -1
- package/dist/transport/multi/multi-transport.test.js +0 -236
- package/dist/transport/rabbitmq/rabbitmq-transport.d.ts +0 -83
- package/dist/transport/rabbitmq/rabbitmq-transport.d.ts.map +0 -1
- package/dist/transport/rabbitmq/rabbitmq-transport.js +0 -541
- package/dist/transport/rabbitmq/rabbitmq-transport.test.d.ts +0 -2
- package/dist/transport/rabbitmq/rabbitmq-transport.test.d.ts.map +0 -1
- package/dist/transport/rabbitmq/rabbitmq-transport.test.js +0 -100
- package/dist/transport/transport.d.ts +0 -152
- package/dist/transport/transport.d.ts.map +0 -1
- package/dist/transport/transport.js +0 -1
- package/dist/types/common.d.ts +0 -41
- package/dist/types/common.d.ts.map +0 -1
- package/dist/types/common.js +0 -12
- package/dist/types/dispatcher.d.ts +0 -14
- package/dist/types/dispatcher.d.ts.map +0 -1
- package/dist/types/dispatcher.js +0 -1
- package/dist/types/envelope.d.ts +0 -131
- package/dist/types/envelope.d.ts.map +0 -1
- package/dist/types/envelope.js +0 -99
- package/dist/types/event.d.ts +0 -96
- package/dist/types/event.d.ts.map +0 -1
- package/dist/types/event.js +0 -26
- package/dist/types/event.test.d.ts +0 -2
- package/dist/types/event.test.d.ts.map +0 -1
- package/dist/types/event.test.js +0 -130
- package/dist/types/index.d.ts +0 -10
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/index.js +0 -4
- package/dist/types/subscriber.d.ts +0 -227
- package/dist/types/subscriber.d.ts.map +0 -1
- package/dist/types/subscriber.js +0 -97
- package/tsconfig.tsbuildinfo +0 -1
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Connection state machine states.
|
|
3
|
-
*/
|
|
4
|
-
export type ConnectionState = {
|
|
5
|
-
readonly status: 'disconnected';
|
|
6
|
-
} | {
|
|
7
|
-
readonly status: 'connecting';
|
|
8
|
-
readonly attempt: number;
|
|
9
|
-
} | {
|
|
10
|
-
readonly status: 'connected';
|
|
11
|
-
} | {
|
|
12
|
-
readonly status: 'reconnecting';
|
|
13
|
-
readonly attempt: number;
|
|
14
|
-
readonly lastError: Error;
|
|
15
|
-
} | {
|
|
16
|
-
readonly status: 'failed';
|
|
17
|
-
readonly error: Error;
|
|
18
|
-
};
|
|
19
|
-
/**
|
|
20
|
-
* Configuration for the connection manager.
|
|
21
|
-
*/
|
|
22
|
-
export interface ConnectionManagerConfig {
|
|
23
|
-
/** Maximum reconnection attempts before giving up (0 = infinite) */
|
|
24
|
-
readonly maxReconnectAttempts: number;
|
|
25
|
-
/** Initial delay between reconnection attempts (ms) */
|
|
26
|
-
readonly initialReconnectDelay: number;
|
|
27
|
-
/** Maximum delay between reconnection attempts (ms) */
|
|
28
|
-
readonly maxReconnectDelay: number;
|
|
29
|
-
/** Backoff multiplier for reconnection delay */
|
|
30
|
-
readonly backoffMultiplier: number;
|
|
31
|
-
/** Heartbeat interval for connection health (ms), optional */
|
|
32
|
-
readonly heartbeatInterval?: number;
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Default configuration values.
|
|
36
|
-
*/
|
|
37
|
-
export declare const defaultConnectionConfig: ConnectionManagerConfig;
|
|
38
|
-
/**
|
|
39
|
-
* Callback for state change notifications.
|
|
40
|
-
*/
|
|
41
|
-
export type StateChangeCallback = (state: ConnectionState) => void;
|
|
42
|
-
/**
|
|
43
|
-
* Function that performs the actual connection.
|
|
44
|
-
*/
|
|
45
|
-
export type ConnectFn = () => Promise<void>;
|
|
46
|
-
/**
|
|
47
|
-
* Function that performs disconnection.
|
|
48
|
-
*/
|
|
49
|
-
export type DisconnectFn = () => Promise<void>;
|
|
50
|
-
/**
|
|
51
|
-
* Manages connection lifecycle with automatic reconnection.
|
|
52
|
-
*/
|
|
53
|
-
export declare class ConnectionManager {
|
|
54
|
-
private readonly connectFn;
|
|
55
|
-
private readonly disconnectFn;
|
|
56
|
-
private _state;
|
|
57
|
-
private readonly listeners;
|
|
58
|
-
private reconnectTimer;
|
|
59
|
-
private readonly config;
|
|
60
|
-
constructor(connectFn: ConnectFn, disconnectFn: DisconnectFn, config?: Partial<ConnectionManagerConfig>);
|
|
61
|
-
/**
|
|
62
|
-
* Current connection state.
|
|
63
|
-
*/
|
|
64
|
-
get state(): ConnectionState;
|
|
65
|
-
/**
|
|
66
|
-
* Whether currently connected.
|
|
67
|
-
*/
|
|
68
|
-
isConnected(): boolean;
|
|
69
|
-
/**
|
|
70
|
-
* Register a callback for connection state changes.
|
|
71
|
-
*/
|
|
72
|
-
onStateChange(callback: StateChangeCallback): () => void;
|
|
73
|
-
/**
|
|
74
|
-
* Attempt to establish connection.
|
|
75
|
-
*/
|
|
76
|
-
connect(): Promise<void>;
|
|
77
|
-
/**
|
|
78
|
-
* Gracefully disconnect.
|
|
79
|
-
*/
|
|
80
|
-
disconnect(): Promise<void>;
|
|
81
|
-
/**
|
|
82
|
-
* Called by transport when connection is lost unexpectedly.
|
|
83
|
-
*/
|
|
84
|
-
handleConnectionLost(error: Error): Promise<void>;
|
|
85
|
-
/**
|
|
86
|
-
* Calculate delay for a given attempt using exponential backoff.
|
|
87
|
-
*/
|
|
88
|
-
calculateDelay(attempt: number): number;
|
|
89
|
-
private setState;
|
|
90
|
-
private handleConnectionFailure;
|
|
91
|
-
private shouldGiveUp;
|
|
92
|
-
private attemptReconnect;
|
|
93
|
-
private clearReconnectTimer;
|
|
94
|
-
}
|
|
95
|
-
//# sourceMappingURL=connection-manager.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"connection-manager.d.ts","sourceRoot":"","sources":["../../src/transport/connection-manager.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,eAAe,GACvB;IAAE,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAA;CAAE,GACnC;IAAE,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GAC3D;IAAE,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAA;CAAE,GAChC;IACE,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAC;IAChC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,SAAS,EAAE,KAAK,CAAC;CAC3B,GACD;IAAE,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAA;CAAE,CAAC;AAEzD;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,oEAAoE;IACpE,QAAQ,CAAC,oBAAoB,EAAE,MAAM,CAAC;IAEtC,uDAAuD;IACvD,QAAQ,CAAC,qBAAqB,EAAE,MAAM,CAAC;IAEvC,uDAAuD;IACvD,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC;IAEnC,gDAAgD;IAChD,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC;IAEnC,8DAA8D;IAC9D,QAAQ,CAAC,iBAAiB,CAAC,EAAE,MAAM,CAAC;CACrC;AAED;;GAEG;AACH,eAAO,MAAM,uBAAuB,EAAE,uBAKrC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG,CAAC,KAAK,EAAE,eAAe,KAAK,IAAI,CAAC;AAEnE;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;AAE5C;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;AAE/C;;GAEG;AACH,qBAAa,iBAAiB;IAO1B,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,YAAY;IAP/B,OAAO,CAAC,MAAM,CAA+C;IAC7D,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAuC;IACjE,OAAO,CAAC,cAAc,CAA8C;IACpE,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA0B;gBAG9B,SAAS,EAAE,SAAS,EACpB,YAAY,EAAE,YAAY,EAC3C,MAAM,GAAE,OAAO,CAAC,uBAAuB,CAAM;IAK/C;;OAEG;IACH,IAAI,KAAK,IAAI,eAAe,CAE3B;IAED;;OAEG;IACH,WAAW,IAAI,OAAO;IAItB;;OAEG;IACH,aAAa,CAAC,QAAQ,EAAE,mBAAmB,GAAG,MAAM,IAAI;IAKxD;;OAEG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAgB9B;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAcjC;;OAEG;IACG,oBAAoB,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC;IASvD;;OAEG;IACH,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM;IAOvC,OAAO,CAAC,QAAQ;YAWF,uBAAuB;IAiBrC,OAAO,CAAC,YAAY;YAON,gBAAgB;IAoB9B,OAAO,CAAC,mBAAmB;CAM5B"}
|
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Default configuration values.
|
|
3
|
-
*/
|
|
4
|
-
export const defaultConnectionConfig = {
|
|
5
|
-
maxReconnectAttempts: 0, // Infinite
|
|
6
|
-
initialReconnectDelay: 1000,
|
|
7
|
-
maxReconnectDelay: 30000,
|
|
8
|
-
backoffMultiplier: 2,
|
|
9
|
-
};
|
|
10
|
-
/**
|
|
11
|
-
* Manages connection lifecycle with automatic reconnection.
|
|
12
|
-
*/
|
|
13
|
-
export class ConnectionManager {
|
|
14
|
-
connectFn;
|
|
15
|
-
disconnectFn;
|
|
16
|
-
_state = { status: 'disconnected' };
|
|
17
|
-
listeners = new Set();
|
|
18
|
-
reconnectTimer = null;
|
|
19
|
-
config;
|
|
20
|
-
constructor(connectFn, disconnectFn, config = {}) {
|
|
21
|
-
this.connectFn = connectFn;
|
|
22
|
-
this.disconnectFn = disconnectFn;
|
|
23
|
-
this.config = { ...defaultConnectionConfig, ...config };
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Current connection state.
|
|
27
|
-
*/
|
|
28
|
-
get state() {
|
|
29
|
-
return this._state;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Whether currently connected.
|
|
33
|
-
*/
|
|
34
|
-
isConnected() {
|
|
35
|
-
return this._state.status === 'connected';
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Register a callback for connection state changes.
|
|
39
|
-
*/
|
|
40
|
-
onStateChange(callback) {
|
|
41
|
-
this.listeners.add(callback);
|
|
42
|
-
return () => this.listeners.delete(callback);
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Attempt to establish connection.
|
|
46
|
-
*/
|
|
47
|
-
async connect() {
|
|
48
|
-
if (this._state.status === 'connected') {
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
this.setState({ status: 'connecting', attempt: 1 });
|
|
52
|
-
try {
|
|
53
|
-
await this.connectFn();
|
|
54
|
-
this.setState({ status: 'connected' });
|
|
55
|
-
}
|
|
56
|
-
catch (error) {
|
|
57
|
-
const err = error instanceof Error ? error : new Error(String(error));
|
|
58
|
-
await this.handleConnectionFailure(err, 1);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Gracefully disconnect.
|
|
63
|
-
*/
|
|
64
|
-
async disconnect() {
|
|
65
|
-
this.clearReconnectTimer();
|
|
66
|
-
if (this._state.status === 'disconnected') {
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
try {
|
|
70
|
-
await this.disconnectFn();
|
|
71
|
-
}
|
|
72
|
-
finally {
|
|
73
|
-
this.setState({ status: 'disconnected' });
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Called by transport when connection is lost unexpectedly.
|
|
78
|
-
*/
|
|
79
|
-
async handleConnectionLost(error) {
|
|
80
|
-
if (this._state.status === 'disconnected') {
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
this.setState({ status: 'reconnecting', attempt: 1, lastError: error });
|
|
84
|
-
await this.attemptReconnect(1);
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Calculate delay for a given attempt using exponential backoff.
|
|
88
|
-
*/
|
|
89
|
-
calculateDelay(attempt) {
|
|
90
|
-
const delay = this.config.initialReconnectDelay *
|
|
91
|
-
Math.pow(this.config.backoffMultiplier, attempt - 1);
|
|
92
|
-
return Math.min(delay, this.config.maxReconnectDelay);
|
|
93
|
-
}
|
|
94
|
-
setState(state) {
|
|
95
|
-
this._state = state;
|
|
96
|
-
for (const listener of this.listeners) {
|
|
97
|
-
try {
|
|
98
|
-
listener(state);
|
|
99
|
-
}
|
|
100
|
-
catch {
|
|
101
|
-
// Ignore listener errors
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
async handleConnectionFailure(error, attempt) {
|
|
106
|
-
if (this.shouldGiveUp(attempt)) {
|
|
107
|
-
this.setState({ status: 'failed', error });
|
|
108
|
-
throw error;
|
|
109
|
-
}
|
|
110
|
-
this.setState({
|
|
111
|
-
status: 'reconnecting',
|
|
112
|
-
attempt: attempt + 1,
|
|
113
|
-
lastError: error,
|
|
114
|
-
});
|
|
115
|
-
await this.attemptReconnect(attempt + 1);
|
|
116
|
-
}
|
|
117
|
-
shouldGiveUp(attempt) {
|
|
118
|
-
return (this.config.maxReconnectAttempts > 0 &&
|
|
119
|
-
attempt >= this.config.maxReconnectAttempts);
|
|
120
|
-
}
|
|
121
|
-
async attemptReconnect(attempt) {
|
|
122
|
-
const delay = this.calculateDelay(attempt);
|
|
123
|
-
await new Promise((resolve) => {
|
|
124
|
-
this.reconnectTimer = setTimeout(resolve, delay);
|
|
125
|
-
});
|
|
126
|
-
if (this._state.status === 'disconnected') {
|
|
127
|
-
return;
|
|
128
|
-
}
|
|
129
|
-
try {
|
|
130
|
-
await this.connectFn();
|
|
131
|
-
this.setState({ status: 'connected' });
|
|
132
|
-
}
|
|
133
|
-
catch (error) {
|
|
134
|
-
const err = error instanceof Error ? error : new Error(String(error));
|
|
135
|
-
await this.handleConnectionFailure(err, attempt);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
clearReconnectTimer() {
|
|
139
|
-
if (this.reconnectTimer !== null) {
|
|
140
|
-
clearTimeout(this.reconnectTimer);
|
|
141
|
-
this.reconnectTimer = null;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export type { TransportCapabilities } from './capabilities.js';
|
|
2
|
-
export { hasNativeDeadLetter, supportsDeliveryMode, supportsDelayedMessages, } from './capabilities.js';
|
|
3
|
-
export type { MessageHandler, MessageReceipt, RabbitMQSendOptions, RabbitMQSubscribeOptions, SendOptions, SubscribeOptions, Subscription, Transport, TransportSendOptions, TransportSubscribeOptions, } from './transport.js';
|
|
4
|
-
export type { ConnectFn, ConnectionManagerConfig, ConnectionState, DisconnectFn, StateChangeCallback, } from './connection-manager.js';
|
|
5
|
-
export { ConnectionManager, defaultConnectionConfig, } from './connection-manager.js';
|
|
6
|
-
export { LocalTransport } from './local/local-transport.js';
|
|
7
|
-
export type { MultiTransportConfig, MultiTransportHooks, } from './multi/multi-transport.js';
|
|
8
|
-
export { MultiTransport } from './multi/multi-transport.js';
|
|
9
|
-
export type { RabbitMQTransportConfig } from './rabbitmq/rabbitmq-transport.js';
|
|
10
|
-
export { RabbitMQTransport } from './rabbitmq/rabbitmq-transport.js';
|
|
11
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/transport/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC/D,OAAO,EACL,mBAAmB,EACnB,oBAAoB,EACpB,uBAAuB,GACxB,MAAM,mBAAmB,CAAC;AAE3B,YAAY,EACV,cAAc,EACd,cAAc,EACd,mBAAmB,EACnB,wBAAwB,EACxB,WAAW,EACX,gBAAgB,EAChB,YAAY,EACZ,SAAS,EACT,oBAAoB,EACpB,yBAAyB,GAC1B,MAAM,gBAAgB,CAAC;AAExB,YAAY,EACV,SAAS,EACT,uBAAuB,EACvB,eAAe,EACf,YAAY,EACZ,mBAAmB,GACpB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,iBAAiB,EACjB,uBAAuB,GACxB,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAE5D,YAAY,EACV,oBAAoB,EACpB,mBAAmB,GACpB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAE5D,YAAY,EAAE,uBAAuB,EAAE,MAAM,kCAAkC,CAAC;AAChF,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC"}
|
package/dist/transport/index.js
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
export { hasNativeDeadLetter, supportsDeliveryMode, supportsDelayedMessages, } from './capabilities.js';
|
|
2
|
-
export { ConnectionManager, defaultConnectionConfig, } from './connection-manager.js';
|
|
3
|
-
export { LocalTransport } from './local/local-transport.js';
|
|
4
|
-
export { MultiTransport } from './multi/multi-transport.js';
|
|
5
|
-
export { RabbitMQTransport } from './rabbitmq/rabbitmq-transport.js';
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { type Logger } from '../../hooks/index.js';
|
|
2
|
-
import type { Topology } from '../../topology/types.js';
|
|
3
|
-
import type { Envelope } from '../../types/index.js';
|
|
4
|
-
import type { TransportCapabilities } from '../capabilities.js';
|
|
5
|
-
import type { MessageHandler, MessageReceipt, SendOptions, SubscribeOptions, Subscription, Transport } from '../transport.js';
|
|
6
|
-
/**
|
|
7
|
-
* Local in-memory transport for testing and fallback.
|
|
8
|
-
* Messages are stored in memory and delivered synchronously.
|
|
9
|
-
*/
|
|
10
|
-
export declare class LocalTransport implements Transport {
|
|
11
|
-
readonly name = "local";
|
|
12
|
-
readonly capabilities: TransportCapabilities;
|
|
13
|
-
private connected;
|
|
14
|
-
private readonly queues;
|
|
15
|
-
private readonly subscriptions;
|
|
16
|
-
private readonly completedMessages;
|
|
17
|
-
private readonly delayedTimers;
|
|
18
|
-
private messageIdCounter;
|
|
19
|
-
private readonly logger;
|
|
20
|
-
constructor(logger?: Logger);
|
|
21
|
-
connect(): Promise<void>;
|
|
22
|
-
disconnect(): Promise<void>;
|
|
23
|
-
isConnected(): boolean;
|
|
24
|
-
applyTopology(topology: Topology): Promise<void>;
|
|
25
|
-
send(queue: string, envelope: Envelope, options?: SendOptions): Promise<Transport['name']>;
|
|
26
|
-
/**
|
|
27
|
-
* Schedules a message for delayed delivery.
|
|
28
|
-
* Returns immediately (non-blocking) to match real transport behavior.
|
|
29
|
-
*/
|
|
30
|
-
private scheduleDelayedMessage;
|
|
31
|
-
private enqueue;
|
|
32
|
-
private deliverToSubscribers;
|
|
33
|
-
subscribe(queue: string, handler: MessageHandler, options?: SubscribeOptions): Promise<Subscription>;
|
|
34
|
-
complete(receipt: MessageReceipt): Promise<void>;
|
|
35
|
-
sendToDeadLetter(receipt: MessageReceipt, dlqName: string, envelope: Envelope, _reason: string): Promise<void>;
|
|
36
|
-
/**
|
|
37
|
-
* Gets the current size of a queue.
|
|
38
|
-
*/
|
|
39
|
-
getQueueSize(queue: string): number;
|
|
40
|
-
/**
|
|
41
|
-
* Gets all completed message receipts.
|
|
42
|
-
*/
|
|
43
|
-
getCompleted(): readonly MessageReceipt[];
|
|
44
|
-
/**
|
|
45
|
-
* Gets pending (uncompleted) messages from a queue.
|
|
46
|
-
*/
|
|
47
|
-
getPendingMessages(queue: string): readonly Envelope[];
|
|
48
|
-
/**
|
|
49
|
-
* Clears all state (for test isolation).
|
|
50
|
-
*/
|
|
51
|
-
clear(): void;
|
|
52
|
-
/**
|
|
53
|
-
* Receives one message from the queue without a subscription.
|
|
54
|
-
* Useful for testing.
|
|
55
|
-
*/
|
|
56
|
-
receiveOne(queue: string): Promise<{
|
|
57
|
-
envelope: Envelope;
|
|
58
|
-
receipt: MessageReceipt;
|
|
59
|
-
} | null>;
|
|
60
|
-
private getOrCreateQueue;
|
|
61
|
-
}
|
|
62
|
-
//# sourceMappingURL=local-transport.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"local-transport.d.ts","sourceRoot":"","sources":["../../../src/transport/local/local-transport.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,MAAM,EAAiB,MAAM,sBAAsB,CAAC;AAClE,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;AAiCzB;;;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,CAAsC;IAC7D,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;IAiBhD,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;YAgBP,oBAAoB;IA+B5B,SAAS,CACb,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,cAAc,EACvB,OAAO,GAAE,gBAAqB,GAC7B,OAAO,CAAC,YAAY,CAAC;IAsClB,QAAQ,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IAMhD,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;IAMnC;;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,241 +0,0 @@
|
|
|
1
|
-
import { TransportNotConnectedError } from '../../errors/index.js';
|
|
2
|
-
import { consoleLogger } from '../../hooks/index.js';
|
|
3
|
-
/**
|
|
4
|
-
* Capabilities of the LocalTransport.
|
|
5
|
-
*/
|
|
6
|
-
const localCapabilities = {
|
|
7
|
-
deliveryModes: ['at-least-once', 'at-most-once'],
|
|
8
|
-
delayedMessages: true, // Implemented with setTimeout
|
|
9
|
-
deadLetterRouting: 'manual',
|
|
10
|
-
attemptTracking: false,
|
|
11
|
-
concurrencyModel: 'none',
|
|
12
|
-
ordering: 'queue',
|
|
13
|
-
priorities: false,
|
|
14
|
-
};
|
|
15
|
-
/**
|
|
16
|
-
* Local in-memory transport for testing and fallback.
|
|
17
|
-
* Messages are stored in memory and delivered synchronously.
|
|
18
|
-
*/
|
|
19
|
-
export class LocalTransport {
|
|
20
|
-
name = 'local';
|
|
21
|
-
capabilities = localCapabilities;
|
|
22
|
-
connected = false;
|
|
23
|
-
queues = new Map();
|
|
24
|
-
subscriptions = new Map();
|
|
25
|
-
completedMessages = [];
|
|
26
|
-
delayedTimers = new Set();
|
|
27
|
-
messageIdCounter = 0;
|
|
28
|
-
logger;
|
|
29
|
-
constructor(logger) {
|
|
30
|
-
this.logger = logger ?? consoleLogger;
|
|
31
|
-
}
|
|
32
|
-
async connect() {
|
|
33
|
-
this.connected = true;
|
|
34
|
-
}
|
|
35
|
-
async disconnect() {
|
|
36
|
-
// Cancel all delayed message timers
|
|
37
|
-
for (const timer of this.delayedTimers) {
|
|
38
|
-
clearTimeout(timer);
|
|
39
|
-
}
|
|
40
|
-
this.delayedTimers.clear();
|
|
41
|
-
// Deactivate all subscriptions
|
|
42
|
-
for (const subs of this.subscriptions.values()) {
|
|
43
|
-
for (const sub of subs) {
|
|
44
|
-
sub.active = false;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
this.connected = false;
|
|
48
|
-
}
|
|
49
|
-
isConnected() {
|
|
50
|
-
return this.connected;
|
|
51
|
-
}
|
|
52
|
-
async applyTopology(topology) {
|
|
53
|
-
if (!this.connected) {
|
|
54
|
-
throw new TransportNotConnectedError(this.name, 'applyTopology');
|
|
55
|
-
}
|
|
56
|
-
// Initialize queues for the topology.
|
|
57
|
-
// Note: Retry queues are not pre-created here because LocalTransport handles
|
|
58
|
-
// retries by re-enqueueing messages with a delay to the original queue, matching
|
|
59
|
-
// how the pipeline schedules retries via transport.send() with a delay option.
|
|
60
|
-
for (const queueDef of topology.queues) {
|
|
61
|
-
const queueName = `${topology.namespace}.${queueDef.name}`;
|
|
62
|
-
if (!this.queues.has(queueName)) {
|
|
63
|
-
this.queues.set(queueName, []);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
async send(queue, envelope, options) {
|
|
68
|
-
if (!this.connected) {
|
|
69
|
-
throw new TransportNotConnectedError(this.name, 'send');
|
|
70
|
-
}
|
|
71
|
-
// Handle delayed messages (non-blocking, like real transports)
|
|
72
|
-
if (options?.delay !== undefined && options.delay > 0) {
|
|
73
|
-
this.scheduleDelayedMessage(queue, envelope, options.delay);
|
|
74
|
-
return this.name;
|
|
75
|
-
}
|
|
76
|
-
await this.enqueue(queue, envelope);
|
|
77
|
-
return this.name;
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Schedules a message for delayed delivery.
|
|
81
|
-
* Returns immediately (non-blocking) to match real transport behavior.
|
|
82
|
-
*/
|
|
83
|
-
scheduleDelayedMessage(queue, envelope, delayMs) {
|
|
84
|
-
const timer = setTimeout(() => {
|
|
85
|
-
this.delayedTimers.delete(timer);
|
|
86
|
-
// Fire and forget - errors are logged in enqueue/deliverToSubscribers
|
|
87
|
-
this.enqueue(queue, envelope).catch((error) => {
|
|
88
|
-
this.logger.error('[Matador] 🔴 Failed to enqueue delayed message', error);
|
|
89
|
-
});
|
|
90
|
-
}, delayMs);
|
|
91
|
-
this.delayedTimers.add(timer);
|
|
92
|
-
}
|
|
93
|
-
async enqueue(queue, envelope) {
|
|
94
|
-
const messages = this.getOrCreateQueue(queue);
|
|
95
|
-
const messageId = `${++this.messageIdCounter}`;
|
|
96
|
-
const queuedMessage = {
|
|
97
|
-
envelope,
|
|
98
|
-
id: messageId,
|
|
99
|
-
completed: false,
|
|
100
|
-
};
|
|
101
|
-
messages.push(queuedMessage);
|
|
102
|
-
// Deliver to any active subscriptions
|
|
103
|
-
await this.deliverToSubscribers(queue, queuedMessage);
|
|
104
|
-
}
|
|
105
|
-
async deliverToSubscribers(queue, message) {
|
|
106
|
-
const subs = this.subscriptions.get(queue);
|
|
107
|
-
if (!subs)
|
|
108
|
-
return;
|
|
109
|
-
for (const sub of subs) {
|
|
110
|
-
if (!sub.active || message.completed)
|
|
111
|
-
continue;
|
|
112
|
-
const receipt = {
|
|
113
|
-
handle: message,
|
|
114
|
-
redelivered: false,
|
|
115
|
-
attemptNumber: message.envelope.docket.attempts,
|
|
116
|
-
deliveryCount: message.envelope.docket.attempts,
|
|
117
|
-
sourceQueue: queue,
|
|
118
|
-
sourceTransport: this.name,
|
|
119
|
-
};
|
|
120
|
-
try {
|
|
121
|
-
await sub.handler(message.envelope, receipt);
|
|
122
|
-
}
|
|
123
|
-
catch (error) {
|
|
124
|
-
// Handler errors should be caught in the pipeline
|
|
125
|
-
this.logger.error('[Matador] 🔴 Handler error in message processing', error);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
async subscribe(queue, handler, options = {}) {
|
|
130
|
-
if (!this.connected) {
|
|
131
|
-
throw new TransportNotConnectedError(this.name, 'subscribe');
|
|
132
|
-
}
|
|
133
|
-
const subscription = {
|
|
134
|
-
handler,
|
|
135
|
-
options,
|
|
136
|
-
active: true,
|
|
137
|
-
};
|
|
138
|
-
const subs = this.subscriptions.get(queue) ?? [];
|
|
139
|
-
subs.push(subscription);
|
|
140
|
-
this.subscriptions.set(queue, subs);
|
|
141
|
-
// Deliver any pending messages
|
|
142
|
-
const messages = this.queues.get(queue) ?? [];
|
|
143
|
-
for (const message of messages) {
|
|
144
|
-
if (message.completed)
|
|
145
|
-
continue;
|
|
146
|
-
await this.deliverToSubscribers(queue, message);
|
|
147
|
-
}
|
|
148
|
-
return {
|
|
149
|
-
unsubscribe: async () => {
|
|
150
|
-
subscription.active = false;
|
|
151
|
-
const remaining = subs.filter((s) => s !== subscription);
|
|
152
|
-
if (remaining.length > 0) {
|
|
153
|
-
this.subscriptions.set(queue, remaining);
|
|
154
|
-
}
|
|
155
|
-
else {
|
|
156
|
-
this.subscriptions.delete(queue);
|
|
157
|
-
}
|
|
158
|
-
},
|
|
159
|
-
get isActive() {
|
|
160
|
-
return subscription.active;
|
|
161
|
-
},
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
async complete(receipt) {
|
|
165
|
-
const message = receipt.handle;
|
|
166
|
-
message.completed = true;
|
|
167
|
-
this.completedMessages.push(receipt);
|
|
168
|
-
}
|
|
169
|
-
async sendToDeadLetter(receipt, dlqName, envelope, _reason) {
|
|
170
|
-
const dlqQueueName = `${receipt.sourceQueue}.${dlqName}`;
|
|
171
|
-
await this.enqueue(dlqQueueName, envelope);
|
|
172
|
-
await this.complete(receipt);
|
|
173
|
-
}
|
|
174
|
-
// Test helpers
|
|
175
|
-
/**
|
|
176
|
-
* Gets the current size of a queue.
|
|
177
|
-
*/
|
|
178
|
-
getQueueSize(queue) {
|
|
179
|
-
const messages = this.queues.get(queue);
|
|
180
|
-
if (!messages)
|
|
181
|
-
return 0;
|
|
182
|
-
return messages.filter((m) => !m.completed).length;
|
|
183
|
-
}
|
|
184
|
-
/**
|
|
185
|
-
* Gets all completed message receipts.
|
|
186
|
-
*/
|
|
187
|
-
getCompleted() {
|
|
188
|
-
return this.completedMessages;
|
|
189
|
-
}
|
|
190
|
-
/**
|
|
191
|
-
* Gets pending (uncompleted) messages from a queue.
|
|
192
|
-
*/
|
|
193
|
-
getPendingMessages(queue) {
|
|
194
|
-
const messages = this.queues.get(queue);
|
|
195
|
-
if (!messages)
|
|
196
|
-
return [];
|
|
197
|
-
return messages.filter((m) => !m.completed).map((m) => m.envelope);
|
|
198
|
-
}
|
|
199
|
-
/**
|
|
200
|
-
* Clears all state (for test isolation).
|
|
201
|
-
*/
|
|
202
|
-
clear() {
|
|
203
|
-
this.queues.clear();
|
|
204
|
-
this.subscriptions.clear();
|
|
205
|
-
this.completedMessages.length = 0;
|
|
206
|
-
this.messageIdCounter = 0;
|
|
207
|
-
for (const timer of this.delayedTimers) {
|
|
208
|
-
clearTimeout(timer);
|
|
209
|
-
}
|
|
210
|
-
this.delayedTimers.clear();
|
|
211
|
-
}
|
|
212
|
-
/**
|
|
213
|
-
* Receives one message from the queue without a subscription.
|
|
214
|
-
* Useful for testing.
|
|
215
|
-
*/
|
|
216
|
-
async receiveOne(queue) {
|
|
217
|
-
const messages = this.queues.get(queue);
|
|
218
|
-
if (!messages)
|
|
219
|
-
return null;
|
|
220
|
-
const pending = messages.find((m) => !m.completed);
|
|
221
|
-
if (!pending)
|
|
222
|
-
return null;
|
|
223
|
-
const receipt = {
|
|
224
|
-
handle: pending,
|
|
225
|
-
redelivered: false,
|
|
226
|
-
attemptNumber: pending.envelope.docket.attempts,
|
|
227
|
-
deliveryCount: pending.envelope.docket.attempts,
|
|
228
|
-
sourceQueue: queue,
|
|
229
|
-
sourceTransport: this.name,
|
|
230
|
-
};
|
|
231
|
-
return { envelope: pending.envelope, receipt };
|
|
232
|
-
}
|
|
233
|
-
getOrCreateQueue(queue) {
|
|
234
|
-
let messages = this.queues.get(queue);
|
|
235
|
-
if (!messages) {
|
|
236
|
-
messages = [];
|
|
237
|
-
this.queues.set(queue, messages);
|
|
238
|
-
}
|
|
239
|
-
return messages;
|
|
240
|
-
}
|
|
241
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"local-transport.test.d.ts","sourceRoot":"","sources":["../../../src/transport/local/local-transport.test.ts"],"names":[],"mappings":""}
|