nats
ModuleThe NATS JetStream broker.
Contents
use utopia_queue::broker::nats::Nats;pub struct NatsThe 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.
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?;
}use utopia_queue::broker::nats::NatsConfig;pub struct NatsConfigHow the NATS broker provisions and drives a queue's streams and consumers.
Default.pub type MessageId = Arc<dyn Fn(&Array) -> String + Send + Sync>Derives a message's deduplication id from its payload.
pub type OnError = Arc<dyn Fn(&Error) + Send + Sync>Where the broker reports failures it cannot raise.