pub struct RoundRobin { /* private fields */ }Expand description
A PublishTransform distributing records round-robin across the first count partitions.
Each record is pinned to 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 record that already names a partition or carries a record key
is left alone: keys exist for ordering, and overriding either would silently break the
caller’s placement.
The cycle writes the same per-record setting the builder’s
partition step writes, so it mounts only over a
publisher whose Publisher::Options are KafkaOptions.
On an Out slot that setting arrives carrying whatever the call site chose, and the cycle
steps aside for it; a reply has no call site, so there the cycle always places.
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
The transform is a step of the mount site’s chain, right after the publish policy:
use ruststream_rdkafka::prelude::*;
#[subscriber("orders", reply)]
async fn plan(order: &Order) -> WorkItem {
WorkItem { order_id: order.id }
}
fn app() -> RustStream {
RustStream::new(AppInfo::new("planner", "0.1.0"))
.with_broker(KafkaBroker::new(["localhost:9092"]), |b| {
b.include(plan)
.out_reply(Publish::default())
.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<K: ContextKind> PublishTransform<K, KafkaOptions> for RoundRobin
impl<K: ContextKind> PublishTransform<K, KafkaOptions> for RoundRobin
Auto Trait Implementations§
impl !Freeze for RoundRobin
impl RefUnwindSafe for RoundRobin
impl Send for RoundRobin
impl Sync for RoundRobin
impl Unpin for RoundRobin
impl UnsafeUnpin for RoundRobin
impl UnwindSafe for RoundRobin
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more