Class DefaultPartitioner
java.lang.Object
org.apache.kafka.clients.producer.internals.DefaultPartitioner
- All Implemented Interfaces:
Closeable,AutoCloseable,Partitioner,org.apache.kafka.common.Configurable
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 -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Deprecated.This is called when partitioner is closed.voidDeprecated.voidonNewBatch(String topic, org.apache.kafka.common.Cluster cluster, int prevPartition) Deprecated.If a batch completed for the current sticky partition, change the sticky partition.intpartition(String topic, Object key, byte[] keyBytes, Object value, byte[] valueBytes, org.apache.kafka.common.Cluster cluster) Deprecated.Compute the partition for the given record.intpartition(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.
-
Constructor Details
-
DefaultPartitioner
public DefaultPartitioner()Deprecated.
-
-
Method Details
-
configure
Deprecated.- Specified by:
configurein interfaceorg.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:
partitionin interfacePartitioner- Parameters:
topic- The topic namekey- 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 nullvalueBytes- serialized value to partition on or nullcluster- 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 namekey- 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 nullvalueBytes- serialized value to partition on or nullcluster- The current cluster metadatanumPartitions- The number of partitions of the giventopic
-
close
public void close()Deprecated.Description copied from interface:PartitionerThis is called when partitioner is closed.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfacePartitioner
-
onNewBatch
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:
onNewBatchin interfacePartitioner- Parameters:
topic- The topic namecluster- The current cluster metadataprevPartition- The partition previously selected for the record that triggered a new batch
-