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§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".