pub struct RoundRobin { /* private fields */ }Expand description
A PublishTransform distributing replies round-robin across the first count partitions.
Each reply gets the PARTITION_HEADER of an incrementing counter modulo count, so the
publisher targets partitions 0..count in a cycle, one message each - the evenest possible
spread for long, near-constant-cost messages. A reply that already carries an explicit
partition or a record key is left alone: keys exist for ordering, and overriding either
would silently break the caller’s placement.
The count is explicit on purpose (cheap and predictable); it must match the destination topic’s partition count, or the tail partitions simply receive nothing (a smaller count) or publishes fail (a larger one).
§Examples
use ruststream::runtime::TypedPublisher;
use ruststream_rdkafka::{KafkaBroker, RoundRobin};
let replies = TypedPublisher::new(broker.publisher()).transform(RoundRobin::partitions(8));Implementations§
Source§impl RoundRobin
impl RoundRobin
Sourcepub fn partitions(count: i32) -> Self
pub fn partitions(count: i32) -> Self
A round-robin cycle over partitions 0..count.
§Panics
Panics when count is zero: a cycle over no partitions cannot place anything.
Trait Implementations§
Source§impl Debug for RoundRobin
impl Debug for RoundRobin
Source§impl<C> PublishTransform<C> for RoundRobin
impl<C> PublishTransform<C> for RoundRobin
Source§fn apply(&self, out: &mut Outgoing<'_>, _cx: &PublishContext<'_, C>)
fn apply(&self, out: &mut Outgoing<'_>, _cx: &PublishContext<'_, C>)
out in place before it is sent, reading the delivery through cx.