There are only a few possible ways to specify partitions while using the Kafka Producer API
- Just specify it in the
ProducerRecord
itself - If key is not null, (by default) Kafka will hash your key and calculate the partition
- If key is null, (by default) Kafka will round-robin b/w all the partitions (to load balance the data)
- If not, just use a custom
Partitioner
If interested, you can also check out the Kafka Partitioning blog
Cheers!