Skip to main content

Partitioner

Trait Partitioner 

Source
pub trait Partitioner<K, V>: Send + Sync {
    // Required method
    fn partition(
        &self,
        topic: &str,
        key: Option<&K>,
        key_bytes: Option<&[u8]>,
        value: Option<&V>,
        value_bytes: Option<&[u8]>,
        cluster: &Cluster,
    ) -> i32;

    // Provided methods
    fn configure(&mut self, _configs: &HashMap<String, String>) { ... }
    fn close(&self) { ... }
}
Expand description

Partitioner Interface

§Translation notes

WARNING: Monitorable is not translated, so a partitioner cannot register metrics.

partition and close take &self: the producer shares one instance across tasks, as Java’s shares it across threads.

Required Methods§

Source

fn partition( &self, topic: &str, key: Option<&K>, key_bytes: Option<&[u8]>, value: Option<&V>, value_bytes: Option<&[u8]>, cluster: &Cluster, ) -> i32

Compute the partition for the given record.

§Arguments
  • topic - The topic name
  • key - The key to partition on (or None if no key)
  • key_bytes - The serialized key to partition on( or None if no key)
  • value - The value to partition on or None
  • value_bytes - The serialized value to partition on or None
  • cluster - The current cluster metadata
§Returns

The partition, non-negative: the send fails on a negative one.

§Translation notes

WARNING: key and value are None on the borrowed send path of KafkaProducer<Vec<u8>, Vec<u8>>.

Provided Methods§

Source

fn configure(&mut self, _configs: &HashMap<String, String>)

Configure this class with the given key-value pairs

§Arguments
  • _configs - the pairs
Source

fn close(&self)

This is called when partitioner is closed.

Implementors§