Class FlinkFixedPartitioner<T>
- java.lang.Object
-
- org.apache.flink.streaming.connectors.kafka.partitioner.FlinkKafkaPartitioner<T>
-
- org.apache.flink.streaming.connectors.kafka.partitioner.FlinkFixedPartitioner<T>
-
- All Implemented Interfaces:
Serializable
@PublicEvolving public class FlinkFixedPartitioner<T> extends FlinkKafkaPartitioner<T>
A partitioner ensuring that each internal Flink partition ends up in one Kafka partition.Note, one Kafka partition can contain multiple Flink partitions.
There are a couple of cases to consider.
More Flink partitions than kafka partitions
Flink Sinks: Kafka Partitions 1 ----------------> 1 2 --------------/ 3 -------------/ 4 ------------/Some (or all) kafka partitions contain the output of more than one flink partition
Fewer Flink partitions than Kafka
Flink Sinks: Kafka Partitions 1 ----------------> 1 2 ----------------> 2 3 4 5Not all Kafka partitions contain data To avoid such an unbalanced partitioning, use a round-robin kafka partitioner (note that this will cause a lot of network connections between all the Flink instances and all the Kafka brokers).
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description FlinkFixedPartitioner()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(Object o)inthashCode()voidopen(int parallelInstanceId, int parallelInstances)Initializer for the partitioner.intpartition(T record, byte[] key, byte[] value, String targetTopic, int[] partitions)Determine the id of the partition that the record should be written to.
-
-
-
Method Detail
-
open
public void open(int parallelInstanceId, int parallelInstances)Description copied from class:FlinkKafkaPartitionerInitializer for the partitioner. This is called once on each parallel sink instance of the Flink Kafka producer. This method should be overridden if necessary.- Overrides:
openin classFlinkKafkaPartitioner<T>- Parameters:
parallelInstanceId- 0-indexed id of the parallel sink instance in FlinkparallelInstances- the total number of parallel instances
-
partition
public int partition(T record, byte[] key, byte[] value, String targetTopic, int[] partitions)
Description copied from class:FlinkKafkaPartitionerDetermine the id of the partition that the record should be written to.- Specified by:
partitionin classFlinkKafkaPartitioner<T>- Parameters:
record- the record valuekey- serialized key of the recordvalue- serialized value of the recordtargetTopic- target topic for the recordpartitions- found partitions for the target topic- Returns:
- the id of the target partition
-
-