kafka::producer

Struct DefaultPartitioner

source
pub struct DefaultPartitioner<H = BuildHasherDefault<DefaultHasher>> { /* private fields */ }
Expand description

As its name implies DefaultPartitioner is the default partitioner for Producer.

For every message it proceeds 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 messages 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.

Implementations§

source§

impl DefaultPartitioner

source

pub fn with_hasher<B: BuildHasher>(hash_builder: B) -> DefaultPartitioner<B>

Creates a new partitioner which will use the given hash builder to hash message keys.

source

pub fn with_default_hasher<B>() -> DefaultPartitioner<BuildHasherDefault<B>>
where B: Hasher + Default,

Trait Implementations§

source§

impl<H: Default> Default for DefaultPartitioner<H>

source§

fn default() -> DefaultPartitioner<H>

Returns the “default value” for a type. Read more
source§

impl<H: BuildHasher> Partitioner for DefaultPartitioner<H>

source§

fn partition(&mut self, topics: Topics<'_>, rec: &mut ProduceMessage<'_, '_>)

Supposed to inspect the given message and if desired re-assign the message’s target partition. Read more

Auto Trait Implementations§

§

impl<H> Freeze for DefaultPartitioner<H>
where H: Freeze,

§

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

§

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

§

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

§

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

§

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

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

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

source§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more