Class UniformStickyPartitioner

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

public class UniformStickyPartitioner
extends Object
implements Partitioner
The partitioning strategy:
  • If a partition is specified in the record, use it
  • Otherwise choose the sticky partition that changes when the batch is full. NOTE: In constrast to the DefaultPartitioner, the record key is NOT used as part of the partitioning strategy in this partitioner. Records with the same key are not guaranteed to be sent to the same partition. See KIP-480 for details about sticky partitioning.
  • Constructor Details

    • UniformStickyPartitioner

      public UniformStickyPartitioner()
  • Method Details

    • configure

      public void configure​(Map<String,​?> configs)
      Description copied from interface: Configurable
      Configure this class with the given key-value pairs
      Specified by:
      configure in interface Configurable
    • 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:
      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
    • close

      public void close()
      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, Cluster cluster, int prevPartition)
      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