pub struct OutboxWorker<OS: OutboxStore, S: As4Sender> { /* private fields */ }Expand description
A background worker that drains the outbox by polling pending
OutboxMessages and dispatching them via an As4Sender.
Obtain via EngineContext::run_outbox_worker and drive by spawning
OutboxWorker::run in a Tokio task.
§Polling behaviour
When the poll returns an empty batch the worker sleeps for poll_interval
before polling again. Non-empty batches are processed immediately.
§Error handling
Successful sends are acknowledged via OutboxStore::acknowledge.
Failed sends are rescheduled via OutboxStore::reschedule using
full-jitter exponential backoff: delay = rand(0, min(MAX, BASE * 2^n))
where n = attempt_count. This avoids thundering-herd when multiple
makod instances restart simultaneously after a receiver outage.
When attempt_count >= max_attempts, the message is acknowledged (removed
from the outbox) and a DeadLetterReason::OutboxExhausted record is written
to the dead-letter sink. This prevents permanently-undeliverable messages
from clogging the outbox forever.
All errors are emitted as structured tracing events at warn / error
level rather than eprintln!, so they appear in the application’s log
pipeline with full context (message_id, error).
§Example
use std::time::Duration;
let worker = ctx.run_outbox_worker(my_sender, 50, Duration::from_secs(1));
tokio::spawn(async move { worker.run().await });