@amqp-contract/worker 0.21.0 → 0.23.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/dist/index.cjs +422 -307
- package/dist/index.d.cts +115 -137
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +115 -137
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +422 -307
- package/dist/index.mjs.map +1 -1
- package/docs/index.md +50 -86
- package/package.json +5 -5
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ConsumerDefinition, ConsumerEntry, ContractDefinition, InferConsumerNames, MessageDefinition } from "@amqp-contract/contract";
|
|
1
|
+
import { ConsumerDefinition, ConsumerEntry, ContractDefinition, InferConsumerNames, InferRpcNames, MessageDefinition, RpcDefinition } from "@amqp-contract/contract";
|
|
2
2
|
import { ConsumerOptions as ConsumerOptions$1, Logger, MessageValidationError, TechnicalError, TelemetryProvider } from "@amqp-contract/core";
|
|
3
3
|
import { Future, Result } from "@swan-io/boxed";
|
|
4
4
|
import * as amqp from "amqplib";
|
|
@@ -212,27 +212,37 @@ type ExtractConsumerDefinition<T extends ConsumerEntry> = T extends ConsumerDefi
|
|
|
212
212
|
*/
|
|
213
213
|
type ConsumerInferPayloadOutput<TConsumer extends ConsumerEntry> = ExtractConsumerDefinition<TConsumer> extends ConsumerDefinition ? InferSchemaOutput<ExtractConsumerDefinition<TConsumer>["message"]["payload"]> : never;
|
|
214
214
|
/**
|
|
215
|
-
* Infer consumer message headers output type
|
|
215
|
+
* Infer consumer message headers output type.
|
|
216
216
|
* Returns undefined if no headers schema is defined.
|
|
217
217
|
*/
|
|
218
218
|
type ConsumerInferHeadersOutput<TConsumer extends ConsumerEntry> = ExtractConsumerDefinition<TConsumer> extends ConsumerDefinition ? ExtractConsumerDefinition<TConsumer>["message"] extends MessageDefinition<infer _TPayload, infer THeaders> ? THeaders extends StandardSchemaV1<Record<string, unknown>> ? InferSchemaOutput<THeaders> : undefined : undefined : undefined;
|
|
219
|
-
/**
|
|
220
|
-
* Infer all consumers from contract
|
|
221
|
-
*/
|
|
222
219
|
type InferConsumers<TContract extends ContractDefinition> = NonNullable<TContract["consumers"]>;
|
|
223
|
-
/**
|
|
224
|
-
* Get specific consumer entry from contract
|
|
225
|
-
*/
|
|
226
220
|
type InferConsumer<TContract extends ContractDefinition, TName extends InferConsumerNames<TContract>> = InferConsumers<TContract>[TName];
|
|
221
|
+
type InferRpcs<TContract extends ContractDefinition> = NonNullable<TContract["rpcs"]>;
|
|
222
|
+
type InferRpc<TContract extends ContractDefinition, TName extends InferRpcNames<TContract>> = InferRpcs<TContract>[TName];
|
|
227
223
|
/**
|
|
228
|
-
* Infer the payload type for a
|
|
224
|
+
* Infer the payload type for a regular consumer (validated against the message schema).
|
|
229
225
|
*/
|
|
230
226
|
type WorkerInferConsumerPayload<TContract extends ContractDefinition, TName extends InferConsumerNames<TContract>> = ConsumerInferPayloadOutput<InferConsumer<TContract, TName>>;
|
|
231
227
|
/**
|
|
232
|
-
* Infer the headers type for a
|
|
233
|
-
* Returns undefined if no headers schema is defined
|
|
228
|
+
* Infer the headers type for a regular consumer.
|
|
229
|
+
* Returns undefined if no headers schema is defined.
|
|
234
230
|
*/
|
|
235
231
|
type WorkerInferConsumerHeaders<TContract extends ContractDefinition, TName extends InferConsumerNames<TContract>> = ConsumerInferHeadersOutput<InferConsumer<TContract, TName>>;
|
|
232
|
+
/**
|
|
233
|
+
* Infer the request payload type for an RPC.
|
|
234
|
+
*/
|
|
235
|
+
type WorkerInferRpcRequest<TContract extends ContractDefinition, TName extends InferRpcNames<TContract>> = InferRpc<TContract, TName> extends RpcDefinition<infer TRequest, MessageDefinition> ? TRequest extends MessageDefinition ? InferSchemaOutput<TRequest["payload"]> : never : never;
|
|
236
|
+
/**
|
|
237
|
+
* Infer the request headers type for an RPC. Returns undefined unless the RPC's
|
|
238
|
+
* request `MessageDefinition` declares a headers schema.
|
|
239
|
+
*/
|
|
240
|
+
type WorkerInferRpcHeaders<TContract extends ContractDefinition, TName extends InferRpcNames<TContract>> = InferRpc<TContract, TName> extends RpcDefinition<infer TRequest, MessageDefinition> ? TRequest extends MessageDefinition<infer _TPayload, infer THeaders> ? THeaders extends StandardSchemaV1<Record<string, unknown>> ? InferSchemaOutput<THeaders> : undefined : undefined : undefined;
|
|
241
|
+
/**
|
|
242
|
+
* Infer the response payload type for an RPC. The handler must return a
|
|
243
|
+
* `Future<Result<TResponse, HandlerError>>` matching this shape.
|
|
244
|
+
*/
|
|
245
|
+
type WorkerInferRpcResponse<TContract extends ContractDefinition, TName extends InferRpcNames<TContract>> = InferRpc<TContract, TName> extends RpcDefinition<MessageDefinition, infer TResponse> ? TResponse extends MessageDefinition ? InferSchemaOutput<TResponse["payload"]> : never : never;
|
|
236
246
|
/**
|
|
237
247
|
* A consumed message containing parsed payload and headers.
|
|
238
248
|
*
|
|
@@ -244,7 +254,6 @@ type WorkerInferConsumerHeaders<TContract extends ContractDefinition, TName exte
|
|
|
244
254
|
*
|
|
245
255
|
* @example
|
|
246
256
|
* ```typescript
|
|
247
|
-
* // Handler receives the consumed message with typed payload and headers
|
|
248
257
|
* const handler = defineHandler(contract, 'processOrder', (message, rawMessage) => {
|
|
249
258
|
* console.log(message.payload.orderId); // Typed payload
|
|
250
259
|
* console.log(message.headers?.priority); // Typed headers (if defined)
|
|
@@ -258,61 +267,57 @@ type WorkerConsumedMessage<TPayload, THeaders = undefined> = {
|
|
|
258
267
|
headers: THeaders extends undefined ? undefined : THeaders;
|
|
259
268
|
};
|
|
260
269
|
/**
|
|
261
|
-
* Infer the full consumed message type for a
|
|
262
|
-
* Includes both payload and headers (if defined).
|
|
270
|
+
* Infer the full consumed message type for a regular consumer.
|
|
263
271
|
*/
|
|
264
272
|
type WorkerInferConsumedMessage<TContract extends ContractDefinition, TName extends InferConsumerNames<TContract>> = WorkerConsumedMessage<WorkerInferConsumerPayload<TContract, TName>, WorkerInferConsumerHeaders<TContract, TName>>;
|
|
265
273
|
/**
|
|
266
|
-
*
|
|
267
|
-
*
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
*
|
|
272
|
-
*
|
|
273
|
-
* The `WorkerInfer*` naming pattern indicates type inference helpers that extract
|
|
274
|
-
* types from a contract definition at compile time.
|
|
275
|
-
*
|
|
276
|
-
* @param message - The parsed message containing validated payload and headers
|
|
277
|
-
* @param rawMessage - The raw AMQP message with all metadata (fields, properties, content)
|
|
278
|
-
*
|
|
279
|
-
* @example
|
|
280
|
-
* ```typescript
|
|
281
|
-
* const handler: WorkerInferConsumerHandler<typeof contract, 'processOrder'> =
|
|
282
|
-
* ({ payload }, rawMessage) => {
|
|
283
|
-
* console.log(payload.orderId); // Typed payload
|
|
284
|
-
* console.log(rawMessage.fields.deliveryTag); // Raw AMQP message
|
|
285
|
-
* return Future.value(Result.Ok(undefined));
|
|
286
|
-
* };
|
|
287
|
-
* ```
|
|
274
|
+
* Infer the consumed message type for an RPC handler — payload + headers from
|
|
275
|
+
* the request side of the RPC.
|
|
276
|
+
*/
|
|
277
|
+
type WorkerInferRpcConsumedMessage<TContract extends ContractDefinition, TName extends InferRpcNames<TContract>> = WorkerConsumedMessage<WorkerInferRpcRequest<TContract, TName>, WorkerInferRpcHeaders<TContract, TName>>;
|
|
278
|
+
/**
|
|
279
|
+
* Handler signature for a regular consumer (event/command). Returns
|
|
280
|
+
* `Future<Result<void, HandlerError>>` — there is no response message.
|
|
288
281
|
*/
|
|
289
282
|
type WorkerInferConsumerHandler<TContract extends ContractDefinition, TName extends InferConsumerNames<TContract>> = (message: WorkerInferConsumedMessage<TContract, TName>, rawMessage: ConsumeMessage) => Future<Result<void, HandlerError>>;
|
|
290
283
|
/**
|
|
291
|
-
* Handler
|
|
292
|
-
*
|
|
293
|
-
*
|
|
294
|
-
*
|
|
295
|
-
*
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
284
|
+
* Handler signature for an RPC. Returns
|
|
285
|
+
* `Future<Result<TResponse, HandlerError>>` where `TResponse` is the inferred
|
|
286
|
+
* response payload. The worker validates the response against the RPC's
|
|
287
|
+
* response schema and publishes it back to `msg.properties.replyTo` with the
|
|
288
|
+
* same `correlationId`.
|
|
289
|
+
*/
|
|
290
|
+
type WorkerInferRpcHandler<TContract extends ContractDefinition, TName extends InferRpcNames<TContract>> = (message: WorkerInferRpcConsumedMessage<TContract, TName>, rawMessage: ConsumeMessage) => Future<Result<WorkerInferRpcResponse<TContract, TName>, HandlerError>>;
|
|
291
|
+
/**
|
|
292
|
+
* Handler entry for a regular consumer — function or `[handler, options]`.
|
|
299
293
|
*/
|
|
300
294
|
type WorkerInferConsumerHandlerEntry<TContract extends ContractDefinition, TName extends InferConsumerNames<TContract>> = WorkerInferConsumerHandler<TContract, TName> | readonly [WorkerInferConsumerHandler<TContract, TName>, ConsumerOptions];
|
|
301
295
|
/**
|
|
302
|
-
*
|
|
303
|
-
|
|
296
|
+
* Handler entry for an RPC — function or `[handler, options]`.
|
|
297
|
+
*/
|
|
298
|
+
type WorkerInferRpcHandlerEntry<TContract extends ContractDefinition, TName extends InferRpcNames<TContract>> = WorkerInferRpcHandler<TContract, TName> | readonly [WorkerInferRpcHandler<TContract, TName>, ConsumerOptions];
|
|
299
|
+
/**
|
|
300
|
+
* All handlers for a contract: one entry per `consumers` key plus one entry
|
|
301
|
+
* per `rpcs` key. The two name spaces are disjoint so the resulting object
|
|
302
|
+
* type is unambiguous.
|
|
304
303
|
*
|
|
305
304
|
* @example
|
|
306
305
|
* ```typescript
|
|
307
|
-
* const handlers:
|
|
306
|
+
* const handlers: WorkerInferHandlers<typeof contract> = {
|
|
308
307
|
* processOrder: ({ payload }) =>
|
|
309
308
|
* Future.fromPromise(processPayment(payload))
|
|
310
309
|
* .mapOk(() => undefined)
|
|
311
310
|
* .mapError((error) => new RetryableError('Payment failed', error)),
|
|
311
|
+
* calculate: ({ payload }) =>
|
|
312
|
+
* Future.value(Result.Ok({ sum: payload.a + payload.b })),
|
|
312
313
|
* };
|
|
313
314
|
* ```
|
|
314
315
|
*/
|
|
315
|
-
type
|
|
316
|
+
type WorkerInferHandlers<TContract extends ContractDefinition> = ([InferConsumerNames<TContract>] extends [never] ? {} : { [K in InferConsumerNames<TContract>]: WorkerInferConsumerHandlerEntry<TContract, K> }) & ([InferRpcNames<TContract>] extends [never] ? {} : { [K in InferRpcNames<TContract>]: WorkerInferRpcHandlerEntry<TContract, K> });
|
|
317
|
+
/**
|
|
318
|
+
* @deprecated Use `WorkerInferHandlers` — handlers now span consumers ∪ rpcs.
|
|
319
|
+
*/
|
|
320
|
+
type WorkerInferConsumerHandlers<TContract extends ContractDefinition> = WorkerInferHandlers<TContract>;
|
|
316
321
|
//#endregion
|
|
317
322
|
//#region src/worker.d.ts
|
|
318
323
|
type ConsumerOptions = ConsumerOptions$1;
|
|
@@ -357,11 +362,16 @@ type ConsumerOptions = ConsumerOptions$1;
|
|
|
357
362
|
type CreateWorkerOptions<TContract extends ContractDefinition> = {
|
|
358
363
|
/** The AMQP contract definition specifying consumers and their message schemas */contract: TContract;
|
|
359
364
|
/**
|
|
360
|
-
* Handlers for each
|
|
361
|
-
*
|
|
362
|
-
*
|
|
365
|
+
* Handlers for each `consumers` and `rpcs` entry in the contract.
|
|
366
|
+
*
|
|
367
|
+
* - Regular consumers return `Future<Result<void, HandlerError>>`.
|
|
368
|
+
* - RPC handlers return `Future<Result<TResponse, HandlerError>>` where
|
|
369
|
+
* `TResponse` is inferred from the RPC's response message schema.
|
|
370
|
+
*
|
|
371
|
+
* Use `defineHandler` / `defineHandlers` to create handlers with full type
|
|
372
|
+
* inference.
|
|
363
373
|
*/
|
|
364
|
-
handlers:
|
|
374
|
+
handlers: WorkerInferHandlers<TContract>; /** AMQP broker URL(s). Multiple URLs provide failover support */
|
|
365
375
|
urls: ConnectionUrl[]; /** Optional connection configuration (heartbeat, reconnect settings, etc.) */
|
|
366
376
|
connectionOptions?: AmqpConnectionManagerOptions | undefined; /** Optional logger for logging message consumption and errors */
|
|
367
377
|
logger?: Logger | undefined;
|
|
@@ -376,6 +386,13 @@ type CreateWorkerOptions<TContract extends ContractDefinition> = {
|
|
|
376
386
|
* Handler-specific options provided in tuple form override these defaults.
|
|
377
387
|
*/
|
|
378
388
|
defaultConsumerOptions?: ConsumerOptions | undefined;
|
|
389
|
+
/**
|
|
390
|
+
* Maximum time in ms to wait for the AMQP connection to become ready before
|
|
391
|
+
* `create()` resolves to `Result.Error<TechnicalError>`. Defaults to 30s
|
|
392
|
+
* (the {@link AmqpClient}'s `DEFAULT_CONNECT_TIMEOUT_MS`). Pass `null` to
|
|
393
|
+
* disable the timeout and let amqp-connection-manager retry indefinitely.
|
|
394
|
+
*/
|
|
395
|
+
connectTimeoutMs?: number | null | undefined;
|
|
379
396
|
};
|
|
380
397
|
/**
|
|
381
398
|
* Type-safe AMQP worker for consuming messages from RabbitMQ.
|
|
@@ -424,13 +441,24 @@ declare class TypedAmqpWorker<TContract extends ContractDefinition> {
|
|
|
424
441
|
private readonly defaultConsumerOptions;
|
|
425
442
|
private readonly logger?;
|
|
426
443
|
/**
|
|
427
|
-
* Internal handler storage
|
|
444
|
+
* Internal handler storage. Keyed by handler name (consumer or RPC); the
|
|
445
|
+
* stored function signature is widened so the dispatch loop can call it
|
|
446
|
+
* uniformly. The actual handler is type-checked at the worker's public API
|
|
447
|
+
* boundary via `WorkerInferHandlers<TContract>`.
|
|
428
448
|
*/
|
|
429
449
|
private readonly actualHandlers;
|
|
430
450
|
private readonly consumerOptions;
|
|
431
451
|
private readonly consumerTags;
|
|
432
452
|
private readonly telemetry;
|
|
433
453
|
private constructor();
|
|
454
|
+
/**
|
|
455
|
+
* Build a `ConsumerDefinition`-shaped view for a handler name, regardless
|
|
456
|
+
* of whether it came from `contract.consumers` or `contract.rpcs`. The
|
|
457
|
+
* dispatch path treats both uniformly; the returned `isRpc` flag (and the
|
|
458
|
+
* accompanying `responseSchema`) tells `processMessage` whether to validate
|
|
459
|
+
* the handler return value and publish a reply.
|
|
460
|
+
*/
|
|
461
|
+
private resolveConsumerView;
|
|
434
462
|
/**
|
|
435
463
|
* Create a type-safe AMQP worker from a contract.
|
|
436
464
|
*
|
|
@@ -463,7 +491,8 @@ declare class TypedAmqpWorker<TContract extends ContractDefinition> {
|
|
|
463
491
|
connectionOptions,
|
|
464
492
|
defaultConsumerOptions,
|
|
465
493
|
logger,
|
|
466
|
-
telemetry
|
|
494
|
+
telemetry,
|
|
495
|
+
connectTimeoutMs
|
|
467
496
|
}: CreateWorkerOptions<TContract>): Future<Result<TypedAmqpWorker<TContract>, TechnicalError>>;
|
|
468
497
|
/**
|
|
469
498
|
* Close the AMQP channel and connection.
|
|
@@ -483,108 +512,57 @@ declare class TypedAmqpWorker<TContract extends ContractDefinition> {
|
|
|
483
512
|
*/
|
|
484
513
|
close(): Future<Result<void, TechnicalError>>;
|
|
485
514
|
/**
|
|
486
|
-
*
|
|
487
|
-
* Defaults are applied in the contract's defineQueue, so we just return the config.
|
|
488
|
-
*/
|
|
489
|
-
private getRetryConfigForConsumer;
|
|
490
|
-
/**
|
|
491
|
-
* Start consuming messages for all consumers.
|
|
492
|
-
* TypeScript guarantees consumers exist (handlers require matching consumers).
|
|
515
|
+
* Start consuming for every entry in `contract.consumers` and `contract.rpcs`.
|
|
493
516
|
*/
|
|
494
517
|
private consumeAll;
|
|
495
518
|
private waitForConnectionReady;
|
|
496
519
|
/**
|
|
497
|
-
* Start consuming messages for a specific
|
|
498
|
-
*
|
|
520
|
+
* Start consuming messages for a specific handler — either a `consumers`
|
|
521
|
+
* entry (regular event/command consumer) or an `rpcs` entry (RPC server).
|
|
499
522
|
*/
|
|
500
523
|
private consume;
|
|
501
524
|
/**
|
|
502
|
-
* Validate data against a Standard Schema
|
|
525
|
+
* Validate data against a Standard Schema. No side effects; the caller is
|
|
526
|
+
* responsible for ack/nack based on the Result.
|
|
503
527
|
*/
|
|
504
528
|
private validateSchema;
|
|
505
529
|
/**
|
|
506
|
-
* Parse and validate a message from AMQP.
|
|
507
|
-
*
|
|
530
|
+
* Parse and validate a message from AMQP. Pure: returns the validated payload
|
|
531
|
+
* and headers, or an error. The dispatch path in {@link processMessage} routes
|
|
532
|
+
* validation/parse errors directly to the DLQ (single nack) — they never enter
|
|
533
|
+
* the retry pipeline because retrying an unparseable or schema-violating
|
|
534
|
+
* payload cannot succeed.
|
|
508
535
|
*/
|
|
509
536
|
private parseAndValidateMessage;
|
|
510
537
|
/**
|
|
511
|
-
*
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
* Handle error in message processing with retry logic.
|
|
516
|
-
*
|
|
517
|
-
* Flow depends on retry mode:
|
|
518
|
-
*
|
|
519
|
-
* **immediate-requeue mode:**
|
|
520
|
-
* 1. If NonRetryableError -> send directly to DLQ (no retry)
|
|
521
|
-
* 2. If max retries exceeded -> send to DLQ
|
|
522
|
-
* 3. Otherwise -> requeue immediately for retry
|
|
523
|
-
*
|
|
524
|
-
* **ttl-backoff mode:**
|
|
525
|
-
* 1. If NonRetryableError -> send directly to DLQ (no retry)
|
|
526
|
-
* 2. If max retries exceeded -> send to DLQ
|
|
527
|
-
* 3. Otherwise -> publish to wait queue with TTL for retry
|
|
528
|
-
*
|
|
529
|
-
* **none mode (no retry config):**
|
|
530
|
-
* 1. send directly to DLQ (no retry)
|
|
531
|
-
*/
|
|
532
|
-
private handleError;
|
|
533
|
-
/**
|
|
534
|
-
* Handle error by requeuing immediately.
|
|
535
|
-
*
|
|
536
|
-
* For quorum queues, messages are requeued with `nack(requeue=true)`, and the worker tracks delivery count via the native RabbitMQ `x-delivery-count` header.
|
|
537
|
-
* For classic queues, messages are re-published on the same queue, and the worker tracks delivery count via a custom `x-retry-count` header.
|
|
538
|
-
* When the count exceeds `maxRetries`, the message is automatically dead-lettered (if DLX is configured) or dropped.
|
|
539
|
-
*
|
|
540
|
-
* This is simpler than TTL-based retry but provides immediate retries only.
|
|
541
|
-
*/
|
|
542
|
-
private handleErrorImmediateRequeue;
|
|
543
|
-
/**
|
|
544
|
-
* Handle error using TTL + wait queue pattern for exponential backoff.
|
|
538
|
+
* Validate an RPC handler's response and publish it back to the caller's reply
|
|
539
|
+
* queue with the same `correlationId`. Published via the AMQP default exchange
|
|
540
|
+
* with `routingKey = msg.properties.replyTo`, which works for both
|
|
541
|
+
* `amq.rabbitmq.reply-to` and any anonymous queue declared by the caller.
|
|
545
542
|
*
|
|
546
|
-
*
|
|
547
|
-
*
|
|
548
|
-
*
|
|
549
|
-
*
|
|
550
|
-
*
|
|
551
|
-
*
|
|
552
|
-
*
|
|
553
|
-
*
|
|
554
|
-
*
|
|
555
|
-
*
|
|
556
|
-
*
|
|
557
|
-
*
|
|
558
|
-
* │ 4. Message waits in queue until TTL expires │
|
|
559
|
-
* │ ↓ │
|
|
560
|
-
* │ 5. Expired message dead-lettered to retry exchange |
|
|
561
|
-
* | (with header `x-retry-queue` set to the main queue name) │
|
|
562
|
-
* │ ↓ │
|
|
563
|
-
* │ 6. Retry exchange routes back to main queue → RETRY │
|
|
564
|
-
* │ ↓ │
|
|
565
|
-
* │ 7. If retries exhausted: nack without requeue → DLQ │
|
|
566
|
-
* │ │
|
|
567
|
-
* └─────────────────────────────────────────────────────────────────┘
|
|
568
|
-
*/
|
|
569
|
-
private handleErrorTtlBackoff;
|
|
570
|
-
/**
|
|
571
|
-
* Calculate retry delay with exponential backoff and optional jitter.
|
|
543
|
+
* Failure semantics:
|
|
544
|
+
* - **Missing replyTo / correlationId**: NonRetryableError. The caller is
|
|
545
|
+
* already lost; retrying the original message cannot recover the reply
|
|
546
|
+
* path. The poison message lands in DLQ for inspection rather than being
|
|
547
|
+
* silently ack'd (which would mask a contract violation).
|
|
548
|
+
* - **Schema validation failure**: NonRetryableError — the handler returned
|
|
549
|
+
* the wrong shape; retrying the same input will not fix it.
|
|
550
|
+
* - **Publish failure**: NonRetryableError. The caller has already timed out
|
|
551
|
+
* (or will shortly), so retrying the message wastes the queue's retry
|
|
552
|
+
* budget on a reply that no one is waiting for. The message is logged and
|
|
553
|
+
* DLQ'd; the original work is treated as completed for the purpose of the
|
|
554
|
+
* inbox.
|
|
572
555
|
*/
|
|
573
|
-
private
|
|
556
|
+
private publishRpcResponse;
|
|
574
557
|
/**
|
|
575
|
-
*
|
|
576
|
-
*
|
|
558
|
+
* Process a single consumed message: validate, invoke handler, optionally
|
|
559
|
+
* publish the RPC response, record telemetry, and handle errors.
|
|
577
560
|
*/
|
|
578
|
-
private
|
|
561
|
+
private processMessage;
|
|
579
562
|
/**
|
|
580
|
-
*
|
|
563
|
+
* Consume messages one at a time.
|
|
581
564
|
*/
|
|
582
|
-
private
|
|
583
|
-
/**
|
|
584
|
-
* Send message to dead letter queue.
|
|
585
|
-
* Nacks the message without requeue, relying on DLX configuration.
|
|
586
|
-
*/
|
|
587
|
-
private sendToDLQ;
|
|
565
|
+
private consumeSingle;
|
|
588
566
|
}
|
|
589
567
|
//#endregion
|
|
590
568
|
//#region src/handlers.d.ts
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":["amqp","EventEmitter","TcpSocketConnectOpts","ConnectionOptions","ChannelWrapper","CreateChannelOpts","ConnectionUrl","Options","Connect","AmqpConnectionOptions","url","connectionOptions","ConnectListener","Connection","connection","arg","ConnectFailedListener","Error","err","Buffer","noDelay","timeout","keepAlive","keepAliveDelay","clientProperties","credentials","mechanism","username","password","response","AmqpConnectionManagerOptions","Promise","heartbeatIntervalInSeconds","reconnectTimeInSeconds","findServers","urls","callback","IAmqpConnectionManager","Function","ChannelModel","addListener","event","args","listener","reason","listeners","eventName","on","once","prependListener","prependOnceListener","removeListener","connect","options","reconnect","createChannel","close","isConnected","channelCount","AmqpConnectionManager","_channels","_currentUrl","_closed","_cancelRetriesHandler","_connectPromise","_currentConnection","_findServers","_urls","constructor","_connect","default"],"sources":["../../../node_modules/.pnpm/amqp-connection-manager@5.0.0_amqplib@1.0.3/node_modules/amqp-connection-manager/dist/types/AmqpConn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EzD;;;;;AA6BA;;;;;;;;;AAyBA;;;;iBAsDgB,SAAA,CAAU,OAAA,UAAiB,KAAA,aAAkB,cAAA;;;;;AAhC7D;;;;;;;;;AAgCA;;;;;;;;;AA8BA;;;;iBAAgB,YAAA,CAAa,OAAA,UAAiB,KAAA,aAAkB,iBAAA;;;;;;
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":["amqp","EventEmitter","TcpSocketConnectOpts","ConnectionOptions","ChannelWrapper","CreateChannelOpts","ConnectionUrl","Options","Connect","AmqpConnectionOptions","url","connectionOptions","ConnectListener","Connection","connection","arg","ConnectFailedListener","Error","err","Buffer","noDelay","timeout","keepAlive","keepAliveDelay","clientProperties","credentials","mechanism","username","password","response","AmqpConnectionManagerOptions","Promise","heartbeatIntervalInSeconds","reconnectTimeInSeconds","findServers","urls","callback","IAmqpConnectionManager","Function","ChannelModel","addListener","event","args","listener","reason","listeners","eventName","on","once","prependListener","prependOnceListener","removeListener","connect","options","reconnect","createChannel","close","isConnected","channelCount","AmqpConnectionManager","_channels","_currentUrl","_closed","_cancelRetriesHandler","_connectPromise","_currentConnection","_findServers","_urls","constructor","_connect","default"],"sources":["../../../node_modules/.pnpm/amqp-connection-manager@5.0.0_amqplib@1.0.3/node_modules/amqp-connection-manager/dist/types/AmqpConnectionManager.d.ts","../src/errors.ts","../src/types.ts","../src/worker.ts","../src/handlers.ts"],"x_google_ignoreList":[0],"mappings":";;;;;;;;;;KAKYM,aAAAA,YAAyBN,IAAAA,CAAKO,OAAAA,CAAQC,OAAAA;EAC9CE,GAAAA;EACAC,iBAAAA,GAAoBF,qBAAAA;AAAAA;AAAAA,KAcZA,qBAAAA,IAAyBN,iBAAAA,GAAoBD,oBAAAA;EACrDkB,OAAAA;EACAC,OAAAA;EACAC,SAAAA;EACAC,cAAAA;EACAC,gBAAAA;EACAC,WAAAA;IACIC,SAAAA;IACAC,QAAAA;IACAC,QAAAA;IACAC,QAAAA,QAAgBV,MAAAA;EAAAA;IAEhBO,SAAA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