[−][src]Struct kafka::producer::DefaultPartitioner
As its name implies DefaultPartitioner
is the default
partitioner for Producer
.
For every message it proceedes as follows:
-
If the messages contains a non-negative partition value it leaves the message untouched. This will cause
Producer
to try to send the message to exactly that partition to. -
Otherwise, if the message has an "unspecified"
partition
- this is, it has a negative partition value - and a specified key,DefaultPartitioner
will compute a hash from the key using the underlying hasher and takehash % num_all_partitions
to derive the partition to send the message to. This will consistently cause messages with the same key to be sent to the same partition. -
Otherwise - a message with an "unspecified"
partition
and no key -DefaultPartitioner
will "randomly" pick one from the "available" partitions trying to distribute the messages across the multiple partitions. In particular, it tries to distribute such messsages across the "available" partitions in a round robin fashion. "Available" it this context means partitions with a known leader.
This behavior may not suffice every workload. If your application
is dependent on a particular distribution scheme different from
the one outlined above, you want to provide your own partioner to
the Producer
at its initialization time.
See Builder::with_partitioner
.
Methods
impl DefaultPartitioner
[src]
pub fn with_hasher<B: BuildHasher>(hash_builder: B) -> DefaultPartitioner<B>
[src]
Creates a new partitioner which will use the given hash builder to hash message keys.
pub fn with_default_hasher<B>() -> DefaultPartitioner<BuildHasherDefault<B>> where
B: Hasher + Default,
[src]
B: Hasher + Default,
Trait Implementations
impl<H: BuildHasher> Partitioner for DefaultPartitioner<H>
[src]
fn partition(&mut self, topics: Topics, rec: &mut ProduceMessage)
[src]
impl<H: Default> Default for DefaultPartitioner<H>
[src]
fn default() -> DefaultPartitioner<H>
[src]
Auto Trait Implementations
impl<H> Unpin for DefaultPartitioner<H> where
H: Unpin,
H: Unpin,
impl<H> Sync for DefaultPartitioner<H> where
H: Sync,
H: Sync,
impl<H> Send for DefaultPartitioner<H> where
H: Send,
H: Send,
impl<H> UnwindSafe for DefaultPartitioner<H> where
H: UnwindSafe,
H: UnwindSafe,
impl<H> RefUnwindSafe for DefaultPartitioner<H> where
H: RefUnwindSafe,
H: RefUnwindSafe,
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,