Skip to main content

KafkaPartitioner

Trait KafkaPartitioner 

Source
pub trait KafkaPartitioner: Send + Sync {
    // Required method
    fn partition(
        &mut self,
        key: Option<&[u8]>,
        num_partitions: i32,
    ) -> Option<i32>;
}
Expand description

Trait for determining the target Kafka partition for a record.

Implementations may be stateful (e.g., round-robin counter).

Required Methods§

Source

fn partition(&mut self, key: Option<&[u8]>, num_partitions: i32) -> Option<i32>

Returns the target partition for the given key.

Returns None if the partitioner defers to the broker (librdkafka) default partitioning.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§