I am trying to store Messages with different key to different partition.
For example:
ProducerRecord<String, String> rec1 = new ProducerRecord<String, String>("topic", "key1", line);
ProducerRecord<String, String> rec2 = new ProducerRecord<String, String>("topic", "key2", line);
producer.send(rec1);
producer.send(rec2);
But when i try to run my Producer class, it always stored in single partition.
As per documentation, DefaultPartitioner
uses message key hash code
to find the partition.
I also saw this question Kafka partition key not working properly, but i cannot find ByteArrayPartitioner
class in 0.9.x version of Kafka Client library.
props.put("partitioner.class", "kafka.producer.ByteArrayPartitioner")
Update: I am creating the topic on the fly using code.
If i create a topic with partitions manually, then its working fine.