import { MessageProcessorMetadata } from '../types'; import { computeBackoffMs } from './backoff'; export type MessageProcessor = (msgPayload: string, metadata?: MessageProcessorMetadata) => Promise; export type ExponentialBackoffOptions = { /** Initial backoff delay in ms. Default: 1_000 (1s). */ baseDelayMs?: number; /** Upper cap for the backoff delay in ms. Default: 1_800_000 (30m). */ maxDelayMs?: number; /** Growth multiplier applied per attempt. Default: 2. */ multiplier?: number; /** Symmetric jitter ratio in [0, 1]. Default: 0.2 (±20%). */ jitterRatio?: number; }; /** * Wrap a message processor so failed processing attempts wait for an * exponentially-growing delay (with jitter) before returning `false` and * letting the library's nack / delay-retry-queue mechanism requeue the * message. * * Why in-processor sleep? * This library sets the retry TTL at queue-declaration time * (queue-level `x-message-ttl`), so per-message exponential delay is not * achievable purely from the broker side. Because consumers use * `prefetch(1)`, sleeping inside the processor only slows the currently * failing queue, which is the desired behaviour when a downstream * dependency is unhealthy. */ export declare const withExponentialBackoff: (processor: MessageProcessor, options?: ExponentialBackoffOptions) => MessageProcessor; export { computeBackoffMs };