@spinajs/queue-stomp-transport 2.0.481 → 2.0.482

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.
@@ -1,15 +1,114 @@
1
1
  import { IQueueMessage, IQueueConnectionOptions, QueueClient, QueueMessage } from '@spinajs/queue';
2
2
  import Stomp from '@stomp/stompjs';
3
3
  import { Constructor } from '@spinajs/di';
4
+ import { ResiliencePipeline } from '@spinajs/util';
5
+ /**
6
+ * Describes a subscription we want to keep alive across reconnects.
7
+ *
8
+ * stompjs does NOT replay subscriptions after a socket drop, so we track the
9
+ * intent ( channel + callback + options ) and re-create the live subscription
10
+ * inside `onConnect` on every ( re )connect.
11
+ */
12
+ interface ISubscriptionDescriptor {
13
+ channel: string;
14
+ callback: (e: IQueueMessage) => Promise<void>;
15
+ subscriptionId?: string;
16
+ durable?: boolean;
17
+ active?: Stomp.StompSubscription;
18
+ }
19
+ /**
20
+ * A message emitted while the client was disconnected. It is buffered and
21
+ * flushed once the connection is ( re )established.
22
+ */
23
+ interface IPendingEmit {
24
+ message: IQueueMessage;
25
+ resolve: () => void;
26
+ reject: (err: unknown) => void;
27
+ }
4
28
  export declare class StompQueueClient extends QueueClient {
5
29
  protected Client: Stomp.Client;
6
- protected Subscriptions: Map<string, Stomp.StompSubscription>;
30
+ protected Subscriptions: Map<string, ISubscriptionDescriptor>;
31
+ protected PendingEmits: IPendingEmit[];
32
+ protected ReadyWaiters: Array<() => void>;
33
+ protected Disposing: boolean;
34
+ /** Publisher-side resilience: retry each receipt-confirmed publish with backoff so a transient
35
+ * broker hiccup / receipt timeout doesn't fail the emit. Duplicates are handled by consumer dedup. */
36
+ protected EmitPipeline: ResiliencePipeline<void>;
7
37
  get ClientId(): string;
38
+ /**
39
+ * `true` when there is an active connection with the broker.
40
+ */
41
+ get Connected(): boolean;
42
+ protected get ReceiptTimeout(): number;
43
+ /**
44
+ * Resolves once the client is connected. If already connected resolves immediately,
45
+ * otherwise waits for the next ( re )connect, optionally bounded by `timeoutMs`.
46
+ */
47
+ whenReady(timeoutMs?: number): Promise<void>;
8
48
  constructor(options: IQueueConnectionOptions);
49
+ /**
50
+ * Creates the underlying stompjs client. Extracted so it can be overridden
51
+ * ( e.g. with a fake ) in unit tests without a live broker.
52
+ */
53
+ protected createClient(config: Stomp.StompConfig): Stomp.Client;
9
54
  resolve(): Promise<void>;
10
55
  dispose(): Promise<void>;
11
56
  emit(message: IQueueMessage): Promise<void>;
12
- unsubscribe(channelOrMessage: string | Constructor<QueueMessage>): void;
57
+ unsubscribe(channelOrMessage: string | Constructor<QueueMessage>, removeDurable?: boolean): void;
13
58
  subscribe(channelOrMessage: string | Constructor<QueueMessage>, callback: (e: IQueueMessage) => Promise<void>, subscriptionId?: string, durable?: boolean): Promise<void>;
59
+ /**
60
+ * Creates the live broker subscription for a tracked descriptor.
61
+ * Called on initial subscribe and replayed for every descriptor on reconnect.
62
+ */
63
+ protected applySubscription(desc: ISubscriptionDescriptor): void;
64
+ /**
65
+ * Handles a message whose consumer callback rejected.
66
+ *
67
+ * Events ( fire-and-forget ) are logged and acked ( dropped ) - the queue model
68
+ * does not retry them. Jobs are retried up to their RetryCount by re-publishing
69
+ * to the same channel with an incremented retry header ( and optional backoff ),
70
+ * then dead-lettered once retries are exhausted.
71
+ */
72
+ protected handleFailedMessage(message: Stomp.IMessage, qMessage: IQueueMessage, desc: ISubscriptionDescriptor, err: unknown): void;
73
+ /**
74
+ * Handles a message whose body could not be parsed as JSON. It cannot be retried
75
+ * ( we don't know its type ), so it is dead-lettered or nacked.
76
+ */
77
+ protected handleUnparseableMessage(message: Stomp.IMessage, channel: string, err: unknown): void;
78
+ /**
79
+ * Publishes a failed message to the given dead-letter channel and acks the original
80
+ * to unblock the source queue. When no dead-letter channel is configured the message is
81
+ * dropped ( acked ) with a warning - we never nack-loop a poison message forever.
82
+ */
83
+ protected deadLetter(message: Stomp.IMessage, dlq: string | undefined, channel: string, reason: string, attempt?: number): void;
84
+ /**
85
+ * Exponential backoff ( ms ) for the given retry attempt, based on `Options.retryDelay`.
86
+ * Returns 0 ( immediate redelivery ) when no base delay is configured.
87
+ */
88
+ protected retryBackoff(attempt: number): number;
89
+ /**
90
+ * Publisher-side resilience pipeline used by emit(). Retries a failed / timed-out receipt
91
+ * publish with exponential backoff ( the per-attempt timeout lives in publishWithReceipt ).
92
+ */
93
+ protected buildEmitPipeline(): ResiliencePipeline<void>;
94
+ /**
95
+ * Publishes a message to all of its routed channels and resolves only once the
96
+ * broker has acknowledged each publish with a RECEIPT frame.
97
+ */
98
+ protected publishMessage(message: IQueueMessage): Promise<void>;
99
+ /**
100
+ * Publishes to a single channel and waits for the broker RECEIPT frame so the
101
+ * caller gets real delivery confirmation ( bounded by `ReceiptTimeout` ).
102
+ */
103
+ protected publishWithReceipt(channel: string, body: string, headers: Stomp.StompHeaders, message: IQueueMessage): Promise<void>;
104
+ /**
105
+ * Flushes messages buffered while disconnected. Called from `onConnect`.
106
+ */
107
+ protected flushPendingEmits(): void;
108
+ /**
109
+ * Resolves everyone waiting on {@link whenReady}. Called from `onConnect`.
110
+ */
111
+ protected flushReadyWaiters(): void;
14
112
  }
113
+ export {};
15
114
  //# sourceMappingURL=connection.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../../src/connection.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,uBAAuB,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACnG,OAAO,KAAK,MAAM,gBAAgB,CAAC;AAEnC,OAAO,EAAE,WAAW,EAAgC,MAAM,aAAa,CAAC;AAOxE,qBAEa,gBAAiB,SAAQ,WAAW;IAC/C,SAAS,CAAC,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC;IAE/B,SAAS,CAAC,aAAa,uCAA8C;IAErE,IAAW,QAAQ,WAElB;gBAEW,OAAO,EAAE,uBAAuB;IAI/B,OAAO;IAmEP,OAAO;IAsBP,I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