Expand description
The open queue contract for nestrs.
nest-rs-queue defines what every queue backend must agree on: the
Job marker, the Processor trait, the ProcessMethod inventory
entry the #[processor] macro submits, and the three pluggable seams a
backend implements — QueueBackend, JobProducer, JobConsumer.
The first-class backend is Redis (via apalis-redis), shipped as
nest-rs-redis. Application code keeps writing nest_rs_queue::* for the
abstractions — the #[processor] macro, Job, Processor,
ProcessMethod, JobProducer — and reaches for nest_rs_redis::* only
when it needs the Redis-specific types (the QueueConnection producer,
the QueueWorker transport, the activation modules). A third-party
nest-rs-<storage> (e.g. SQS, NATS, in-memory) depends on this crate
directly — see this crate’s README for the extension contract.
Structs§
- Process
Method - Link-time inventory entry submitted by
#[processor]for each#[process]-tagged method. AJobConsumerdrains this registry at boot and filters byReachableProvidersso a method on a provider not reachable from the app’s module tree is skipped with a bootwarn(the consumer logs it, so leftover code stays visible). - Processor
Meta - Runtime metadata for one consumer, surfaced via
DiscoveryServicefor the classic struct-level#[processor]form. New code usesProcessMethoddirectly; this type remains for backends that consumeProcessorMetaviaDiscoveryService::meta::<ProcessorMeta>().
Enums§
- Queue
Error - A failure enqueuing a job through a
JobProducer(or thepushconvenience over it).
Constants§
- WIRE_
FORMAT_ VERSION - Wire-format version every backend wraps jobs with on push and unwraps on
dispatch. Bumping it lets a
#[processor]handler reject payloads from a newer release (rolling-deploy safety) instead of misinterpreting bytes.
Traits§
- From
Container - Queue analog of
#[injectable]’sfrom_container, expressed as a trait so a backend can build any processor generically from the container. - Job
- JSON-round-trippable + Clone (retry keeps a copy) + cross-task safe.
- JobConsumer
- Drains a list of
#[process]methods until cancellation. One per app — theTransporta queue backend contributes typically wraps aJobConsumerand forwards the cancellation token. - JobProducer
- Backend-agnostic producer: push a JSON-serialized job onto a named queue.
Concrete backends implement this; typed pushes are a convenience built on
top via
JobProducerExt. - JobProducer
Ext - Typed-push convenience over any
JobProducer. Lives as an extension trait so the producer trait stays object-safe (Arc<dyn JobProducer>). - Processor
- A returned
Errmarks the job failed; the backend retries up to the#[process(retries = N)]budget. - Queue
Backend - A queue backend, identified by name for boot diagnostics. The actual
runtime work happens through
JobProducer(enqueue) andJobConsumer(drainProcessMethodand dispatch). A backend’s module typically: - Queue
Name - The type-level identity of a queue: its wire name plus the
Jobpayload it carries. Implemented by thequeuemacro on a unit struct living beside the payload at the feature port:
Type Aliases§
- JobHandler
- Type-erased async job handler the
#[processor]macro emits for each#[process]method. Backends invoke it with a JSON payload pulled off their wire; the closure deserializes to the user’s job type, resolves the provider from the container, and dispatches.
Attribute Macros§
- async_
trait - processor
- Orchestrator on an
#[injectable]provider’simplblock. Each method tagged with#[process(queue = "...", concurrency, retries)]becomes a queue consumer theQueueWorkerspawns at boot. - queue
- Stamp a unit struct with a compile-time queue identity — its wire name and
the
Jobpayload it carries — by implementingQueueName. Lives beside the payload at the feature port; both the producer (push_to::<Q>) and the consumer (#[process(queue = Q)]) name the type, so a typo’d name or a mismatched payload is a compile error, not a job that silently never drains.