kafka multi-partition 只有一个可以接收消息
kafka multi-partition only one can receive message
我是 kafka.I 的新手,阅读快速入门并创建一个名为 'test' 的主题,有 4 个分区,但是当向该主题发送消息时,我发现所有消息都保存在分区 0 中,为什么其他三个分区是空的?
有我的 java 发送消息的代码
for (int i = 0; i < 100; i++){
producer.send(new ProducerRecord<String, String>("test", "message",Integer.toString(i)));
}
请参考javadoc
If no partition is specified but a key is present a partition will be chosen using a hash of the key.
由于您传递的是同一个密钥,因此它被发送到同一个分区。
for (int i = 0; i < 100; i++){
producer.send(new ProducerRecord<String, String>("test", "message"+i,Integer.toString(i)));
}
我已将消息随机化为 "message"+i
我是 kafka.I 的新手,阅读快速入门并创建一个名为 'test' 的主题,有 4 个分区,但是当向该主题发送消息时,我发现所有消息都保存在分区 0 中,为什么其他三个分区是空的?
有我的 java 发送消息的代码
for (int i = 0; i < 100; i++){
producer.send(new ProducerRecord<String, String>("test", "message",Integer.toString(i)));
}
请参考javadoc
If no partition is specified but a key is present a partition will be chosen using a hash of the key.
由于您传递的是同一个密钥,因此它被发送到同一个分区。
for (int i = 0; i < 100; i++){
producer.send(new ProducerRecord<String, String>("test", "message"+i,Integer.toString(i)));
}
我已将消息随机化为 "message"+i