Rust

nats

Module

The NATS JetStream broker.

Contents

use utopia_queue::broker::nats::Nats;
Rust
pub struct Nats

The NATS JetStream broker (Broker\Nats): each queue is a work-queue stream Q_<NAME> with one subject q.<name>.normal served by the durable pull consumer worker, and a dead stream Q_<NAME>_DEAD on q.<name>.dead.

Redelivery and dead-lettering are the server's: a rejected message is NAK'd with the tier backoff and redelivered until max_deliver, then terminated and copied to the dead stream; a terminal message goes there at once. A worker that dies is reclaimed by ack_wait redelivery, so Nats::reap does nothing. Every publish carries its pid as Nats-Msg-Id, so a retried publish inside the duplicate window is stored once, and the codec's Content-Type header.

Rust
use utopia_queue::broker::{Nats, NatsConfig};
use utopia_queue::{Consumer, Publisher, Queue};

let broker = Nats::new("nats://localhost:4222", NatsConfig::default())?;
let queue = Queue::new("audits")?;
broker.publish(&queue, utopia_queue::payload(&serde_json::json!({"event": "login"}))?).await?;
for message in broker.receive(&queue, 1, 10).await? {
    broker.commit(&queue, &message).await?;
}
Compiles in CI; needs a running service to execute.
use utopia_queue::broker::nats::NatsConfig;
Rust
pub struct NatsConfig

How the NATS broker provisions and drives a queue's streams and consumers.

Also implements Default.
Rust
pub type MessageId = Arc<dyn Fn(&Array) -> String + Send + Sync>

Derives a message's deduplication id from its payload.

Rust
pub type OnError = Arc<dyn Fn(&Error) + Send + Sync>

Where the broker reports failures it cannot raise.