Skip to main content

KafkaPartitioner

Trait KafkaPartitioner 

Source
pub trait KafkaPartitioner: Send + Sync {
    // Required methods
    fn partition(
        &mut self,
        key: Option<&[u8]>,
        num_partitions: i32,
    ) -> Option<i32>;
    fn reset(&mut self);
}
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.

Source

fn reset(&mut self)

Resets the partitioner state (e.g., on epoch boundary).

Implementors§