Skip to main content

KeyColumn

Trait KeyColumn 

Source
pub trait KeyColumn {
    // Required method
    fn key(&self) -> Option<&[u8]>;
}
Expand description

The type of a field playing partition_key: the bytes the delivery’s key lends.

§Examples

use ruststream_sqlx::prelude::*;
use serde::Deserialize;
use sqlx::PgPool;

#[derive(Inbox, sqlx::FromRow)]
#[inbox(table = "order_jobs")]
pub struct OrderJob {
    #[field(id, generated)]
    id: i64,
    // A `String` lends its bytes as the delivery's key; an empty `Option` gives none.
    #[field(partition_key)]
    customer: Option<String>,
    #[field(payload)]
    payload: Vec<u8>,
}

#[derive(Deserialize)]
struct Order {
    id: u64,
}

#[subscriber(InboxQueue::<OrderJob>::new("orders"))]
async fn fulfil(order: &Order) -> HandlerOutcome {
    tracing::info!(order.id, "fulfilling");
    HandlerOutcome::ack()
}

pub fn app(pool: PgPool) -> RustStream {
    RustStream::new(AppInfo::new("orders", "0.1.0")).with_broker(SqlxBroker::new(pool), |b| {
        // Four workers, and the orders of one customer keep their order on one of them.
        b.include(fulfil.workers_by_key(nonzero!(4)));
    })
}

Required Methods§

Source

fn key(&self) -> Option<&[u8]>

The key’s bytes, or None when the row carries no key.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementations on Foreign Types§

Source§

impl KeyColumn for Box<[u8]>

Source§

fn key(&self) -> Option<&[u8]>

Source§

impl KeyColumn for Box<str>

Source§

fn key(&self) -> Option<&[u8]>

Source§

impl KeyColumn for String

Source§

fn key(&self) -> Option<&[u8]>

Source§

impl KeyColumn for Vec<u8>

Source§

fn key(&self) -> Option<&[u8]>

Source§

impl<T: KeyColumn> KeyColumn for Option<T>

Source§

fn key(&self) -> Option<&[u8]>

Implementors§