| title | services.queue — the job queue service API |
|---|---|
| navTitle | services.queue |
| description | Publish and subscribe to async job queues with services.queue — queue size, purge, and dead-letter listing, replay and cleanup for failed messages. |
- Stability:
stable - Canonical source:
packages/spec/src/contracts/queue-service.ts - Registry slot:
queue— resolve withctx.getService('queue').
services.queue.publish<T = unknown>(queue: string, data: T, options?: QueuePublishOptions): Promise<string>
services.queue.subscribe<T = unknown>(queue: string, handler: QueueHandler<T>): Promise<void>
services.queue.subscribeBatch?<T = unknown>(queue: string, handler: QueueBatchHandler<T>, options: QueueBatchSubscribeOptions): Promise<void>
services.queue.unsubscribe(queue: string): Promise<void>
services.queue.getQueueSize?(queue: string): Promise<number>
services.queue.purge?(queue: string): Promise<void>
services.queue.listFailed?(queue?: string, options?: { limit?: number; offset?: number }): Promise<QueueMessageRecord[]>
services.queue.replay?(messageId: string): Promise<void>
services.queue.purgeFailed?(messageId: string): Promise<void>subscribeBatch is optional. It hands the handler up to options.maxBatch messages of one queue per call, and the handler answers one QueueBatchOutcome per message, in order: { ok: true }, or { ok: false, error }. A failed message takes the same retry and dead-letter path alone, while its neighbours complete. A handler that throws, or answers a different number of outcomes, fails every message of that call. A queue takes either per-message handlers or one batch handler, and unsubscribe removes either. A queue service without subscribeBatch is consumed one message at a time with subscribe. The database queue implements it.
MESSAGE_NOT_FOUND—replaycalled with an unknown message id. (purgeFailedis idempotent — an unknown id is a silent no-op.)INVALID_STATE—replay/purgeFailedcalled on a message that is not in thedlqorfailedstate.