0

Note: Kafka version used: kafka_2.11-0.9.0.1

I have 1 topic named test-kafka which as 3 partitions and 1 replication factor and this topic has some string data i.e. key and value pair in each partition.

when I am trying to fetch records via consumer api, consumer.poll function isn't fetching any record and giving records.count =0 however when I use the same logic with just a single parition then it works well and fetches the record.

What I thought was that Kafka will internally take care of multiple partitions and will get me the records one by one from each partition and I just need to subscribe to a topic.

Anyone can help here ?

Code snippet for reference:

KafkaConsumer<String,String> consumer = new KafkaConsumer<String,String>(props);
        consumer.subscribe(Arrays.asList(topic));

        while(true)
        {
            ConsumerRecords<String, String> records = consumer.poll(100);

            System.out.println(records.count());

            for(ConsumerRecord<String,String> record: records)
            {
                System.out.printf("Key: %s, Value = %s", record.key(), record.value());
            }

        }

Above code is returning "zero" in records count.

1 Answers1

0

Try using a longer poll interval. I tried 100 ms with my topics but the call timed out before any messages could be retrieved. Changing to 1000 ms worked for me.

Chris Gerken
  • 16,221
  • 6
  • 44
  • 59