rabbitmq-with-retry-and-dlq 1.0.23 → 1.0.25
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 +247 -134
- package/dist/consumerMq.d.ts +126 -3
- package/dist/consumerMq.d.ts.map +1 -1
- package/dist/consumerMq.js +363 -56
- package/dist/consumerMq.js.map +1 -1
- package/dist/publisherMq.d.ts +2 -70
- package/dist/publisherMq.d.ts.map +1 -1
- package/dist/publisherMq.js +76 -235
- package/dist/publisherMq.js.map +1 -1
- package/dist/types.d.ts +13 -12
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +7 -1
- package/dist/types.js.map +1 -1
- package/package.json +1 -1
package/dist/consumerMq.d.ts
CHANGED
|
@@ -76,8 +76,11 @@ declare class RabbitMQConsumer extends EventEmitter {
|
|
|
76
76
|
* await consumer.assertQueues(['orders-worker', 'payments-worker']);
|
|
77
77
|
*
|
|
78
78
|
* @example
|
|
79
|
-
* // Assert queue with
|
|
79
|
+
* // Assert queue with exchange binding and retry config
|
|
80
80
|
* await consumer.assertQueues('orders-worker', {
|
|
81
|
+
* exchangeName: 'orders',
|
|
82
|
+
* exchangeType: 'direct',
|
|
83
|
+
* routingKey: 'order.created',
|
|
81
84
|
* retryConfig: { maxRetries: 3, retryDelayMs: 5000 }
|
|
82
85
|
* });
|
|
83
86
|
*/
|
|
@@ -85,12 +88,44 @@ declare class RabbitMQConsumer extends EventEmitter {
|
|
|
85
88
|
durable?: boolean;
|
|
86
89
|
exclusive?: boolean;
|
|
87
90
|
autoDelete?: boolean;
|
|
91
|
+
exchangeName?: string;
|
|
92
|
+
exchangeType?: 'direct' | 'topic' | 'fanout' | 'headers';
|
|
93
|
+
routingKey?: string;
|
|
88
94
|
retryConfig?: RetryConfig;
|
|
89
95
|
}): Promise<void>;
|
|
90
96
|
/**
|
|
91
|
-
*
|
|
97
|
+
* Delete queues (Best Practice for cleanup/testing)
|
|
98
|
+
* Can be called with a single queue name or multiple queue names
|
|
99
|
+
* Also deletes associated retry and DLQ queues if they exist
|
|
100
|
+
*
|
|
101
|
+
* @param queueNames - Single queue name (string) or array of queue names
|
|
102
|
+
* @param options - Delete options (includeRetry, includeDLQ)
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* // Delete a single queue
|
|
106
|
+
* await consumer.deleteQueues('orders');
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* // Delete multiple queues
|
|
110
|
+
* await consumer.deleteQueues(['orders', 'payments', 'notifications']);
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* // Delete queue without retry/DLQ queues
|
|
114
|
+
* await consumer.deleteQueues('orders', {
|
|
115
|
+
* includeRetry: false,
|
|
116
|
+
* includeDLQ: false
|
|
117
|
+
* });
|
|
92
118
|
*/
|
|
93
|
-
|
|
119
|
+
deleteQueues(queueNames: string | string[], options?: {
|
|
120
|
+
/** Whether to delete associated retry queue (default: true) */
|
|
121
|
+
includeRetry?: boolean;
|
|
122
|
+
/** Whether to delete associated DLQ (default: true) */
|
|
123
|
+
includeDLQ?: boolean;
|
|
124
|
+
}): Promise<void>;
|
|
125
|
+
/**
|
|
126
|
+
* Setup Dead Letter Queue (DLQ) infrastructure for a queue with retry mechanism
|
|
127
|
+
*/
|
|
128
|
+
private setupDLQInfrastructure;
|
|
94
129
|
/**
|
|
95
130
|
* Bind a queue to an exchange with a routing key (Best Practice for Consumers)
|
|
96
131
|
* Consumers decide which exchanges/routing keys they want to subscribe to
|
|
@@ -118,6 +153,43 @@ declare class RabbitMQConsumer extends EventEmitter {
|
|
|
118
153
|
exchangeType?: 'direct' | 'topic' | 'fanout' | 'headers';
|
|
119
154
|
durable?: boolean;
|
|
120
155
|
}): Promise<void>;
|
|
156
|
+
/**
|
|
157
|
+
* Setup a complete queue with exchange and bindings in ONE atomic operation
|
|
158
|
+
* This is the RECOMMENDED method to prevent race conditions
|
|
159
|
+
*
|
|
160
|
+
* All operations (exchange, queue, bindings) happen in a single setup callback,
|
|
161
|
+
* guaranteeing correct order of execution.
|
|
162
|
+
*
|
|
163
|
+
* @param config - Queue setup configuration
|
|
164
|
+
*
|
|
165
|
+
* @example
|
|
166
|
+
* await consumer.setupQueue({
|
|
167
|
+
* queueName: 'orders-processor',
|
|
168
|
+
* exchangeName: 'orders',
|
|
169
|
+
* exchangeType: 'topic',
|
|
170
|
+
* routingKeys: ['order.created', 'order.updated'],
|
|
171
|
+
* retryConfig: { maxRetries: 3, retryDelayMs: 5000 }
|
|
172
|
+
* });
|
|
173
|
+
*
|
|
174
|
+
* @example
|
|
175
|
+
* // Setup multiple queues
|
|
176
|
+
* await consumer.setupQueue({
|
|
177
|
+
* queueName: 'fiat.account.create',
|
|
178
|
+
* exchangeName: 'user-accounts',
|
|
179
|
+
* exchangeType: 'topic',
|
|
180
|
+
* routingKeys: ['account.fiat.create', 'account.create']
|
|
181
|
+
* });
|
|
182
|
+
*/
|
|
183
|
+
setupQueue(config: {
|
|
184
|
+
queueName: string;
|
|
185
|
+
exchangeName: string;
|
|
186
|
+
exchangeType: 'direct' | 'topic' | 'fanout' | 'headers';
|
|
187
|
+
routingKeys: string | string[];
|
|
188
|
+
durable?: boolean;
|
|
189
|
+
exclusive?: boolean;
|
|
190
|
+
autoDelete?: boolean;
|
|
191
|
+
retryConfig?: RetryConfig;
|
|
192
|
+
}): Promise<void>;
|
|
121
193
|
/**
|
|
122
194
|
* List of error codes that are considered retryable (transient errors)
|
|
123
195
|
* These errors indicate temporary failures that may succeed on retry
|
|
@@ -139,10 +211,61 @@ declare class RabbitMQConsumer extends EventEmitter {
|
|
|
139
211
|
private calculateRetryDelay;
|
|
140
212
|
/**
|
|
141
213
|
* Consume messages from a queue with automatic retry and DLQ handling
|
|
214
|
+
*
|
|
215
|
+
* Note: Queue should be set up separately before consuming:
|
|
216
|
+
* - Use assertQueues() to create queue with exchange binding
|
|
217
|
+
* - Use setupQueue() for complete setup with multiple routing keys
|
|
218
|
+
* - Use bindQueue() to add additional routing key bindings
|
|
219
|
+
*
|
|
220
|
+
* @example
|
|
221
|
+
* // Step 1: Setup queue with exchange and routing keys
|
|
222
|
+
* await consumer.setupQueue({
|
|
223
|
+
* queueName: 'orders',
|
|
224
|
+
* exchangeName: 'orders',
|
|
225
|
+
* exchangeType: 'topic',
|
|
226
|
+
* routingKeys: ['order.created', 'order.updated'],
|
|
227
|
+
* retryConfig: { maxRetries: 5 }
|
|
228
|
+
* });
|
|
229
|
+
*
|
|
230
|
+
* // Step 2: Consume (queue already set up)
|
|
231
|
+
* await consumer.consumeQueue({
|
|
232
|
+
* queueName: 'orders',
|
|
233
|
+
* onMessage: async (message) => {
|
|
234
|
+
* await processOrder(message);
|
|
235
|
+
* }
|
|
236
|
+
* });
|
|
237
|
+
*
|
|
238
|
+
* @example
|
|
239
|
+
* // Direct queue consumption (no exchange)
|
|
240
|
+
* await consumer.assertQueues('simple-queue');
|
|
241
|
+
* await consumer.consumeQueue({
|
|
242
|
+
* queueName: 'simple-queue',
|
|
243
|
+
* onMessage: async (message) => { ... }
|
|
244
|
+
* });
|
|
142
245
|
*/
|
|
143
246
|
consumeQueue<T = any>(config: ConsumeConfig<T>): Promise<void>;
|
|
144
247
|
/**
|
|
145
248
|
* Consume from multiple queues with the same connection
|
|
249
|
+
* Note: Queues should be set up separately before consuming
|
|
250
|
+
*
|
|
251
|
+
* @example
|
|
252
|
+
* // Setup queues first
|
|
253
|
+
* await consumer.setupQueue({ queueName: 'orders', ... });
|
|
254
|
+
* await consumer.setupQueue({ queueName: 'payments', ... });
|
|
255
|
+
*
|
|
256
|
+
* // Then consume from all
|
|
257
|
+
* await consumer.consumeMultipleQueues({
|
|
258
|
+
* queues: [
|
|
259
|
+
* {
|
|
260
|
+
* queueName: 'orders',
|
|
261
|
+
* onMessage: async (msg) => { ... }
|
|
262
|
+
* },
|
|
263
|
+
* {
|
|
264
|
+
* queueName: 'payments',
|
|
265
|
+
* onMessage: async (msg) => { ... }
|
|
266
|
+
* }
|
|
267
|
+
* ]
|
|
268
|
+
* });
|
|
146
269
|
*/
|
|
147
270
|
consumeMultipleQueues<T = any>(config: MultiQueueConsumeConfig<T>): Promise<void>;
|
|
148
271
|
/**
|
package/dist/consumerMq.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"consumerMq.d.ts","sourceRoot":"","sources":["../consumerMq.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,
|
|
1
|
+
{"version":3,"file":"consumerMq.d.ts","sourceRoot":"","sources":["../consumerMq.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EASL,aAAa,EACb,WAAW,EACX,uBAAuB,EAIvB,iBAAiB,EACjB,WAAW,EACZ,MAAM,SAAS,CAAC;AAGjB,cAAM,gBAAiB,SAAQ,YAAY;IACzC,OAAO,CAAC,UAAU,CAAC,CAA6B;IAChD,OAAO,CAAC,OAAO,CAAC,CAAsB;IAC/B,SAAS,EAAE,MAAM,CAAC;IACzB,OAAO,CAAC,WAAW,CAAkB;IACrC,OAAO,CAAC,YAAY,CAAgB;IACpC,OAAO,CAAC,wBAAwB,CAAS;IACzC,OAAO,CAAC,mBAAmB,CAAS;IAEpC,OAAO,CAAC,qBAAqB,CAAC,CAAgB;IAE9C;;;;;;;;;;;;;;;OAeG;gBACS,OAAO,CAAC,EAAE,MAAM,GAAG,iBAAiB;IAiBhD;;;OAGG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAuFjC;;;;OAIG;YACW,gBAAgB;IAsB9B;;OAEG;IACH,mBAAmB,IAAI,OAAO;IAI9B;;;;;;;;;;;;;;OAcG;IACG,cAAc,CAClB,aAAa,EAAE,MAAM,GAAG,MAAM,EAAE,EAChC,OAAO,GAAE;QACP,YAAY,CAAC,EAAE,QAAQ,GAAG,OAAO,GAAG,QAAQ,GAAG,SAAS,CAAC;QACzD,O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