Trait rdkafka::producer::Partitioner
source · pub trait Partitioner {
// Required method
fn partition(
&self,
topic_name: &str,
key: Option<&[u8]>,
partition_cnt: i32,
is_partition_available: impl Fn(i32) -> bool
) -> i32;
}
Expand description
Trait allowing to customize the partitioning of messages.
Required Methods§
sourcefn partition(
&self,
topic_name: &str,
key: Option<&[u8]>,
partition_cnt: i32,
is_partition_available: impl Fn(i32) -> bool
) -> i32
fn partition( &self, topic_name: &str, key: Option<&[u8]>, partition_cnt: i32, is_partition_available: impl Fn(i32) -> bool ) -> i32
Return partition to use for topic_name
.
topic_name
is the name of a topic to which a message is being produced.
partition_cnt
is the number of partitions for this topic.
key
is an optional key of the message.
is_partition_available
is a function that can be called to check if a partition has an active leader broker.
It may be called in any thread at any time, It may be called multiple times for the same message/key. MUST NOT block or execute for prolonged periods of time. MUST return a value between 0 and partition_cnt-1, or the special RD_KAFKA_PARTITION_UA value if partitioning could not be performed. See documentation for rd_kafka_topic_conf_set_partitioner_cb from librdkafka for more info.