runmq 1.5.0 → 2.0.0
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/README.md +105 -106
- package/dist/index.cjs +341 -144
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +46 -3
- package/dist/index.d.ts +46 -3
- package/dist/index.js +341 -144
- package/dist/index.js.map +1 -1
- package/package.json +5 -2
package/dist/index.d.ts
CHANGED
|
@@ -22,15 +22,49 @@ interface RunMQConnectionConfig {
|
|
|
22
22
|
username: string;
|
|
23
23
|
password: string;
|
|
24
24
|
};
|
|
25
|
+
/**
|
|
26
|
+
* Controls publisher confirms on the user-publish path. When enabled
|
|
27
|
+
* (default), `runMQ.publish()` resolves only after RabbitMQ acknowledges
|
|
28
|
+
* each message, and rejects on broker error (e.g. mandatory routing
|
|
29
|
+
* failure, alarm state). Set to `false` to opt out and fall back to
|
|
30
|
+
* fire-and-forget — publish resolves once the message is written to the
|
|
31
|
+
* TCP socket, with no delivery guarantee.
|
|
32
|
+
*
|
|
33
|
+
* Trade-off: confirms add a broker round-trip per publish (typically a
|
|
34
|
+
* few hundred microseconds). They're the only way to detect silent
|
|
35
|
+
* publish failures, so we default to safety. DLQ publishes from the
|
|
36
|
+
* consumer chain are *always* confirmed regardless of this setting —
|
|
37
|
+
* the message-loss risk there is not negotiable.
|
|
38
|
+
*/
|
|
39
|
+
usePublisherConfirms?: boolean;
|
|
40
|
+
logFullMessagePayload?: boolean;
|
|
25
41
|
}
|
|
26
42
|
type SchemaFailureStrategy = 'dlq';
|
|
27
43
|
type SchemaType = 'ajv';
|
|
28
44
|
interface RunMQProcessorConfiguration {
|
|
29
45
|
name: string;
|
|
30
46
|
/**
|
|
31
|
-
* The number of concurrent consumers
|
|
47
|
+
* The number of concurrent consumers (independent AMQP channels) to run
|
|
48
|
+
* for this processor.
|
|
49
|
+
*
|
|
50
|
+
* Each consumer holds its own channel with its own `prefetch` window, so
|
|
51
|
+
* the maximum number of unacknowledged in-flight messages for the
|
|
52
|
+
* processor is `consumersCount * prefetch` — not `prefetch` alone.
|
|
53
|
+
* For example, `consumersCount: 10` with the default `prefetch: 20`
|
|
54
|
+
* allows up to 200 messages to be held unacknowledged at once.
|
|
55
|
+
*
|
|
56
|
+
* Tune both values together to control memory footprint and the size of
|
|
57
|
+
* the redelivery surface on a crash.
|
|
32
58
|
*/
|
|
33
59
|
consumersCount: number;
|
|
60
|
+
/**
|
|
61
|
+
* The per-channel prefetch count applied to each consumer's channel.
|
|
62
|
+
* Defaults to 20.
|
|
63
|
+
*
|
|
64
|
+
* NOTE: this is per-consumer, not per-processor. Total in-flight messages
|
|
65
|
+
* for the processor is `consumersCount * prefetch`.
|
|
66
|
+
*/
|
|
67
|
+
prefetch?: number;
|
|
34
68
|
/**
|
|
35
69
|
* The maximum number attempts processing a message, default is 1 attempt.
|
|
36
70
|
*/
|
|
@@ -119,6 +153,7 @@ declare class RunMQ {
|
|
|
119
153
|
private readonly logger;
|
|
120
154
|
private retryAttempts;
|
|
121
155
|
private defaultChannel;
|
|
156
|
+
private publishChannel;
|
|
122
157
|
private constructor();
|
|
123
158
|
/**
|
|
124
159
|
* Starts the RunMQ instance by establishing a connection to RabbitMQ and initializing necessary components.
|
|
@@ -135,12 +170,20 @@ declare class RunMQ {
|
|
|
135
170
|
*/
|
|
136
171
|
process<T = Record<string, never>>(topic: string, config: RunMQProcessorConfiguration, processor: (message: RunMQMessageContent<T>) => Promise<void>): Promise<void>;
|
|
137
172
|
/**
|
|
138
|
-
* Publishes a message to the specified topic with an optional correlation ID
|
|
173
|
+
* Publishes a message to the specified topic with an optional correlation ID.
|
|
174
|
+
*
|
|
175
|
+
* If publisher confirms are enabled (`usePublisherConfirms: true` in the
|
|
176
|
+
* connection config), the returned promise resolves only after RabbitMQ
|
|
177
|
+
* acknowledges the message; if the broker rejects, the promise rejects.
|
|
178
|
+
* Otherwise it resolves once the message is flushed to the TCP socket
|
|
179
|
+
* (fire-and-forget, no delivery guarantee — same behavior as before
|
|
180
|
+
* publisher confirms were introduced).
|
|
181
|
+
*
|
|
139
182
|
* @param topic The name of the topic to publish the message to
|
|
140
183
|
* @param message The message payload to be published
|
|
141
184
|
* @param correlationId (Optional) A unique identifier for correlating messages; if not provided, a new UUID will be generated
|
|
142
185
|
*/
|
|
143
|
-
publish(topic: string, message: Record<string, any>, correlationId?: string): void
|
|
186
|
+
publish(topic: string, message: Record<string, any>, correlationId?: string): Promise<void>;
|
|
144
187
|
/**
|
|
145
188
|
* Disconnects from RabbitMQ, handling any errors that may occur during the disconnection process.
|
|
146
189
|
*/
|