Class DefaultPartitioner

java.lang.Object
org.apache.kafka.clients.producer.internals.DefaultPartitioner
All Implemented Interfaces:
Closeable, AutoCloseable, Partitioner, org.apache.kafka.common.Configurable

@Deprecated public class DefaultPartitioner extends Object implements Partitioner
Deprecated.
NOTE this partitioner is deprecated and shouldn't be used. To use default partitioning logic remove partitioner.class configuration setting. See KIP-794 for more info. The default partitioning strategy:
  • If a partition is specified in the record, use it
  • If no partition is specified but a key is present choose a partition based on a hash of the key
  • If no partition or key is present choose the sticky partition that changes when the batch is full. See KIP-480 for details about sticky partitioning.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Deprecated.
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Deprecated.
    This is called when partitioner is closed.
    void
    configure(Map<String,?> configs)
    Deprecated.
     
    void
    onNewBatch(String topic, org.apache.kafka.common.Cluster cluster, int prevPartition)
    Deprecated.
    If a batch completed for the current sticky partition, change the sticky partition.
    int
    partition(String topic, Object key, byte[] keyBytes, Object value, byte[] valueBytes, org.apache.kafka.common.Cluster cluster)
    Deprecated.
    Compute the partition for the given record.
    int
    partition(String topic, Object key, byte[] keyBytes, Object value, byte[] valueBytes, org.apache.kafka.common.Cluster cluster, int numPartitions)
    Deprecated.
    Compute the partition for the given record.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • DefaultPartitioner

      public DefaultPartitioner()
      Deprecated.
  • Method Details

    • configure

      public void configure(Map<String,?> configs)
      Deprecated.
      Specified by:
      configure in interface org.apache.kafka.common.Configurable
    • partition

      public int partition(String topic, Object key, byte[] keyBytes, Object value, byte[] valueBytes, org.apache.kafka.common.Cluster cluster)
      Deprecated.
      Compute the partition for the given record.
      Specified by:
      partition in interface Partitioner
      Parameters:
      topic - The topic name
      key - The key to partition on (or null if no key)
      keyBytes - serialized key to partition on (or null if no key)
      value - The value to partition on or null
      valueBytes - serialized value to partition on or null
      cluster - The current cluster metadata
    • partition

      public int partition(String topic, Object key, byte[] keyBytes, Object value, byte[] valueBytes, org.apache.kafka.common.Cluster cluster, int numPartitions)
      Deprecated.
      Compute the partition for the given record.
      Parameters:
      topic - The topic name
      key - The key to partition on (or null if no key)
      keyBytes - serialized key to partition on (or null if no key)
      value - The value to partition on or null
      valueBytes - serialized value to partition on or null
      cluster - The current cluster metadata
      numPartitions - The number of partitions of the given topic
    • close

      public void close()
      Deprecated.
      Description copied from interface: Partitioner
      This is called when partitioner is closed.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in interface Partitioner
    • onNewBatch

      public void onNewBatch(String topic, org.apache.kafka.common.Cluster cluster, int prevPartition)
      Deprecated.
      If a batch completed for the current sticky partition, change the sticky partition. Alternately, if no sticky partition has been determined, set one.
      Specified by:
      onNewBatch in interface Partitioner
      Parameters:
      topic - The topic name
      cluster - The current cluster metadata
      prevPartition - The partition previously selected for the record that triggered a new batch