Class RoundRobinPartitioner
java.lang.Object
org.apache.kafka.clients.producer.RoundRobinPartitioner
- All Implemented Interfaces:
Closeable,AutoCloseable,Partitioner,Configurable
The "Round-Robin" partitioner
This partitioning strategy can be used when user wants
to distribute the writes to all partitions equally. This
is the behaviour regardless of record key hash.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()This is called when partitioner is closed.voidConfigure this class with the given key-value pairsvoidonNewBatch(String topic, Cluster cluster, int prevPartition) Note this method is only implemented in DefaultPartitioner andUniformStickyPartitionerwhich are now deprecated.intpartition(String topic, Object key, byte[] keyBytes, Object value, byte[] valueBytes, Cluster cluster) Compute the partition for the given record.
-
Constructor Details
-
RoundRobinPartitioner
public RoundRobinPartitioner()
-
-
Method Details
-
configure
Description copied from interface:ConfigurableConfigure this class with the given key-value pairs- Specified by:
configurein interfaceConfigurable
-
partition
public int partition(String topic, Object key, byte[] keyBytes, Object value, byte[] valueBytes, Cluster cluster) 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
-
onNewBatch
Description copied from interface:PartitionerNote this method is only implemented in DefaultPartitioner andUniformStickyPartitionerwhich are now deprecated. See KIP-794 for more info.Notifies the partitioner a new batch is about to be created. When using the sticky partitioner, this method can change the chosen sticky partition for the new batch.
After onNewBatch, the
Partitioner.partition(String, Object, byte[], Object, byte[], Cluster)method is called again which allows the implementation to "redirect" the message on new batch creation.- 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
-
close
public void close()Description copied from interface:PartitionerThis is called when partitioner is closed.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfacePartitioner
-