Skip to main content

Partitioner

Trait Partitioner 

Source
pub trait Partitioner: Send + Sync {
    // Required method
    fn partition(
        &self,
        topic: &str,
        key: Option<&[u8]>,
        value: Option<&[u8]>,
        available_partitions: &[PartitionInfo],
        all_partitions: &[PartitionInfo],
    ) -> i32;
}
Expand description

A caller-supplied partitioner.class hook (Kafka’s Partitioner interface).

Producer::builder().partitioner(...) installs one. send then calls it, instead of the built-in partitioner, for every record with no explicit partition — keyed or not. A negative result fails the send with crate::ProducerError::InvalidPartitionerResult, the message Kafka’s KafkaProducer.partition throws. Setting a partitioner also turns adaptive partitioning off, matching Kafka’s enableAdaptivePartitioning = partitionerPlugin.get() == null && ....

Required Methods§

Source

fn partition( &self, topic: &str, key: Option<&[u8]>, value: Option<&[u8]>, available_partitions: &[PartitionInfo], all_partitions: &[PartitionInfo], ) -> i32

Pick the partition of a record. available_partitions holds the partitions of topic that have a leader; all_partitions holds every partition. Kafka’s Partitioner.partition takes the unserialized and the serialized key and value; this trait takes only the serialized forms, which is what the producer already holds at partitioning time.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§