Hi! I'm doing a Kafka exercise using Scala to deal with the Consumer API.
But, I'm having a little problem: I can't iterate over the records that I get from my polling.
Follow the code:
val consumerTest: KafkaConsumer[String,String] = new KafkaConsumer[String, String](props)
consumerTest.subscribe(Collections
.singletonList("teste"))
try{
while(true) {
val records: ConsumerRecords[String, String] = consumerTest.poll(1000)
for(record <- records) {
println(s"offset = ${record.offset()}, key = ${record.key()}, value = ${record.value()}")
}
}
} catch {
case e: KafkaException => println("there was a exception")
} finally {
consumerTest.close()
}
The error I'm getting is: "value foreach is no a member of org.apache.kafka.clients.consumer.ConsumerRecords[String, String]", in the for statement.
I tried using the iterator method from ConsumerRecords, but I get the same error.
If someone could help me, I'll be really glad.
Thanks!