I am testing a simple code in which I am trying to produce some messages to a single topic t having three partitions. Since I'm using high-level producer I am expecting that all the messages would get distributed evenly among those three partitions but strangely all the messages are going to partition 0 only. Following is my code
var kafka = require('kafka-node'),
HighLevelProducer = kafka.HighLevelProducer,
client = new kafka.Client(),
producer = new HighLevelProducer(client),
payloads = [
{ topic: 't', messages: ['hi','Bye','kay','Nai'] }
];
producer.on('ready', function () {
for(let i=0;i<=10000;i++){
producer.send(payloads, function (err, data) {
if(!err){
console.log(data);
} else {
console.log(err)
}
});
}
});
producer.on('error', function (err) {
"use strict";
console.log(err)
})
Note: topic t exist and that has three partitions
Can somebody please point me what is the issue or am I making any mistake in my assumptions?
If you are using the old zookeeper based client you will need to call client.refreshMetadata() before sending your messages. The new KafkaClient does not suffer from this issue since it automatically fetches the metadata upon connect.
@hyperlink I'm using new KafkaClient and HighLevelProducer, but still the producer sending to only one partition. Version - 3.0.1
@joynal +1
Same here (January 2020). The only way I can get the producer to produce to different partitions is to set the partition manually on the message payload which is not optimal. Please help, thank you.
Most helpful comment
@hyperlink I'm using new KafkaClient and HighLevelProducer, but still the producer sending to only one partition. Version - 3.0.1