[][src]Struct kafka::producer::DefaultPartitioner

pub struct DefaultPartitioner<H = BuildHasherDefault<DefaultHasher>> { /* fields omitted */ }

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 take hash % 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]

Trait Implementations

impl<H: BuildHasher> Partitioner for DefaultPartitioner<H>[src]

impl<H: Default> Default for DefaultPartitioner<H>[src]

Auto Trait Implementations

impl<H> Unpin for DefaultPartitioner<H> where
    H: Unpin

impl<H> Sync for DefaultPartitioner<H> where
    H: Sync

impl<H> Send for DefaultPartitioner<H> where
    H: Send

impl<H> UnwindSafe for DefaultPartitioner<H> where
    H: UnwindSafe

impl<H> RefUnwindSafe for DefaultPartitioner<H> where
    H: RefUnwindSafe

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,