We have a kafka producer-consumer setup in Java (using spring-kafka, but probably that is not relevant here). The key used is String and value is custom POJO. The producer-consumer communicate over a single topic test-topic having 16 partitions. The consumer has a concurrency of 16 so that it can read from each partition in parallel.
From the documentation & other references I understand that - Using null keys will distribute the messages sent by the publisher in the partitions in a round-robin fashion. It is advisable to use non-null keys if I am interested in distributing the messages to specific partitions derived using keys
I have the following queries here -
- Currently, the producer sends unique key per message. As this is a unique
Stringper message, in almost all the cases it will generate a unique hashcode as well. How will the messages get distributed here, will it be round-robin likenullkeys or some hash logic that repeats the use of partitions or any other control mechanism? - Is there any pro or con of using keys with strategy as mentioned above over
nullkeys? - I have no requirement of maintaining the order or grouping of messages. In this case is it sensible to use
nullkeys or is it still nice to have a unique or non-unique non-null key per message, if yes, why? - The consumers are reading the messages in batches. Does having or not having a key impact batch reads differently from singular reads?
