Skip to main content

Module dlq

Module dlq 

Source
Available on crate feature dlq only.
Expand description

Unified dead letter queue (DLQ) with pluggable backends.

Provides a shared DLQ abstraction for all DFE services. Failed messages are routed to one or more backends (file, Kafka, or custom) using configurable cascade or fan-out modes.

§Backends

  • File: NDJSON files with automatic rotation and cleanup. Always available, no external dependencies.
  • Kafka: Routes to Kafka topics with per-table or common routing. Requires the dlq-kafka feature.
  • HTTP: POSTs entries as NDJSON. Requires the dlq-http feature.
  • Redis: XADDs entries to a Redis Stream. Requires the dlq-redis feature.

Backends are selected and configured via DlqConfig; consumers never construct backend types directly. To add a new backend, extend the DlqBackend enum in rustlib itself.

§Modes

  • Cascade (default): Try backends in order, stop on first success.
  • Fan-out: Write to all backends, succeed if any succeed.
  • FileOnly: File backend only (no Kafka dependency).
  • KafkaOnly: Kafka backend only.

§Example

use hyperi_rustlib::dlq::{Dlq, DlqConfig, DlqEntry, DlqSource};
use tokio_util::sync::CancellationToken;

let config = DlqConfig::default();
let shutdown = CancellationToken::new();
let dlq = Dlq::spawn(&config, "my-service", None, shutdown.clone())?;

let entry = DlqEntry::new("my-service", "parse_error", b"bad data".to_vec())
    .with_destination("acme.auth")
    .with_source(DlqSource::kafka("events", 1, 42));

dlq.send(entry).await?;       // queued (non-blocking)
dlq.flush().await?;           // wait for durable write
shutdown.cancel();
dlq.shutdown().await?;        // drain + exit

Structs§

Dlq
Unified DLQ. Caller queues entries from any task; the orchestrator drains them off-runtime via the configured backends.
DlqConfig
Top-level DLQ configuration.
DlqEntry
A failed message routed to the dead letter queue.
DlqSource
Source metadata for a DLQ entry.
FileDlqConfig
File-based DLQ configuration.
HttpDlqConfig
Configuration for the HTTP DLQ backend.
RedisDlqConfig
Configuration for the Redis DLQ backend.

Enums§

DlqBackend
A DLQ backend. One variant per supported destination.
DlqError
Errors from DLQ operations.
DlqMode
How backends are used when multiple are enabled.
RotationPeriodio
File rotation period.

Type Aliases§

Result
Result type for DLQ operations.