DefaultPartitioner — Default Partitioning Strategy

DefaultPartitioner is a Partitioner that uses a 32-bit murmur2 hash to compute the partition for a record (with the key defined) or chooses a partition in a round-robin fashion (per the available partitions of the topic).

DefaultPartitioner is the default partitioning strategy (per ProducerConfig.PARTITIONER_CLASS_CONFIG configuration property).

DefaultPartitioner is a Configurable that needs no configuration while being created.

DefaultPartitioner does nothing when requested to close.

Computing Partition For Record — partition Method

int partition(
  String topic,
  Object key,
  byte[] keyBytes,
  Object value,
  byte[] valueBytes,
  Cluster cluster)
Note
partition is part of the Partitioner Contract to compute the partition for a record.

partition requests the input Cluster for the partitions for the given topic.

If there is the keyBytes serialized key present (i.e. non-null), partition simply generates a 32-bit murmur2 hash (from the byte array) and applies the modulo operation by the number of partitions.

If there is no keyBytes serialized key defined (i.e. null), partition requests the input Cluster for the availablePartitionsForTopic and chooses a partition in a round-robin fashion.

nextValue Internal Method

int nextValue(String topic)

nextValue…​FIXME

Note
nextValue is used exclusively when DefaultPartitioner is requested for the partition for a record.

results matching ""

    No results matching ""