Skip to main content

RedisPublishSteps

Trait RedisPublishSteps 

Source
pub trait RedisPublishSteps {
    // Required method
    fn partition_key(self, key: impl AsRef<[u8]>) -> Self;
}
Expand description

The steps this crate adds to the publish builder.

Import it from any of this crate’s preludes to reach partition_key on a publish over a Redis publisher. The impl is bounded on RedisPublishOptions, so the step does not appear on a builder over another broker’s publisher.

§Examples

use ruststream_fred::stream::prelude::*;
use serde::{Deserialize, Serialize};

#[derive(Deserialize, Serialize, Outgoing)]
#[outgoing(name = "orders")]
struct Order {
    tenant: String,
    id: u64,
}

#[derive(OutSlot)]
#[publishes(Order)]
struct Orders;

// Every order of one tenant lands in the same `workers(n, by_key)` lane downstream, so their
// relative order is preserved while other tenants run in parallel.
#[subscriber(RedisStream::new("orders.in").group("intake"))]
async fn intake(
    order: &Order,
    Out(orders): Out<impl Publisher<Options = RedisPublishOptions>, Orders>,
) -> HandlerOutcome {
    match orders.message(order).partition_key(&order.tenant).publish().await {
        Ok(_) => HandlerOutcome::ack(),
        Err(_) => HandlerOutcome::retry(),
    }
}

#[ruststream::app]
fn app() -> impl App {
    RustStream::new(AppInfo::new("orders", "0.1.0")).with_broker(
        RedisBroker::standalone("redis://localhost:6379"),
        |b| {
            b.include(intake).out(Orders, Publish).build();
        },
    )
}

Required Methods§

Source

fn partition_key(self, key: impl AsRef<[u8]>) -> Self

Sends this one message under key, whatever the rest of the chain says.

The key feeds the runtime’s keyed worker lanes (workers(n, by_key)): deliveries sharing a key are dispatched to the same lane, so their relative order survives concurrency. It reaches the consumer as the PARTITION_KEY_HEADER header, written over whatever the call site itself put under that name.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<Sink, Body, Enc, Hdrs, Dest> RedisPublishSteps for PublishBuilder<Sink, Body, Enc, Hdrs, Dest>
where Sink: PublishSink<Options = RedisPublishOptions>,

Source§

fn partition_key(self, key: impl AsRef<[u8]>) -> Self

Implementors§