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§
Sourcefn partition(
&self,
topic: &str,
key: Option<&K>,
key_bytes: Option<&[u8]>,
value: Option<&V>,
value_bytes: Option<&[u8]>,
cluster: &Cluster,
) -> i32
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 namekey- 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 Nonevalue_bytes- The serialized value to partition on or Nonecluster- 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>>.