Rust

background

Module

Background dispatch on top of a synchronous publisher.

Contents

use utopia_queue::broker::background::Background;
Rust
pub struct Background<P>

The buffer's capacity is the back pressure: once full, enqueue waits for a slot up to timeout seconds (negative: forever) and then fails with Error::BufferFull. With a batch interval and size, consecutive messages for one queue are coalesced into publish_many calls, a partial batch leaving when its oldest message reaches the interval. Before Background::start (and after Background::shutdown) enqueue publishes synchronously. More than one reader gives up FIFO order.

Rust
use std::sync::Arc;
use utopia_queue::broker::{Background, Redis};
use utopia_queue::connection::Redis as Connection;
use utopia_queue::{AsyncPublisher, Queue};

let redis = Arc::new(Redis::new(Arc::new(Connection::new("localhost", 6379)), Arc::new(Connection::new("localhost", 6379))));
let background = Background::new(redis, 512, 1, -1.0, None)?;
background.start()?;
background.enqueue(&Queue::new("audits")?, utopia_queue::payload(&serde_json::json!({"event": "login"}))?).await?;
background.shutdown().await;
Compiles in CI; needs a running service to execute.
Rust
pub type Log = Arc<dyn Fn(&str) + Send + Sync>

Where dispatch failures are written (stderr by default): there is no producer left to report them to.