注意的多个分区数据:使用kafka_2.11-0.9.0.1为什么卡夫卡消费者API不获取由一个主题
我已经创建了一个名为卡夫卡话题:consumer-tutorials
与3 Partitions
如下:
C:\kafka_2.11-0.9.0.1>.\bin\windows\kafka-topics.bat --describe --topic consumer-tutorial
--zookeeper localhost:2181
Topic:consumer-tutorial PartitionCount:3 ReplicationFactor:1 Configs:
Topic: consumer-tutorial Partition: 0 Leader: 0 Replicas: 0 Isr: 0
Topic: consumer-tutorial Partition: 1 Leader: 0 Replicas: 0 Isr: 0
Topic: consumer-tutorial Partition: 2 Leader: 0 Replicas: 0 Isr: 0
一旦创建过主题,我使用Producer API按照以下生产的每个分区中的一些数据:
KafkaProducer<String,String> prod = new KafkaProducer<String,String>(props);
for(int i =0; i < 3; i++)
{
for(int x=start; x<end; x++)
{
prod.send(new ProducerRecord<String,String>("consumer-tutorial",i,Integer.toString(x),Integer.toString(rnd.nextInt(100)))); }
start=end;
end = start + 10;
}
prod.close();
现在,当我试图获取记录/ CON使用以下Consumer API
这个话题庙消息:
KafkaConsumer<String,String> consumer = new KafkaConsumer<String,String>(props);
consumer.subscribe(Arrays.asList("consumer-tutorial"));
while(true)
{
ConsumerRecords<String, String> records = consumer.poll(100);
for(ConsumerRecord<String,String> record: records)
{
System.out.printf("Key: %s, Value = %s", record.key(), record.value());
}
}
同时运行此代码,我没有得到任何记录。我检查record
变量,但没有KEY:VALUE
对从Poll
Watch on "records" shows nothing
未来谁能帮助我,为什么我没有得到任何要显示的数据。
NOTE: It works well when I have single partition topic.