Reputation: 119
Kafka Consumer API Committed returns null offset. Not sure what is wrong.
val partitions = new util.HashSet[TopicPartition]
for (partitionInfo <- consumer.partitionsFor(topic)) {
partitions.add(new TopicPartition(partitionInfo.topic, partitionInfo.partition))
}
consumer.assign(partitions)
val latestOffset= consumer.committed(partitions)
println ("LatestOffset Object "+ latestOffset)
val map = latestOffset.map{ case(t, o) => t.partition() -> o.offset()}
output of print:
{partition-1=null, partition-0=null}
End result i want to get a map of partition->offset like {"0"->200,"1"->100}
Why LatestOffset Object Offset metadata shows null? If I use consumer.position it works.
Using kafka client :
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka-clients</artifactId>
<version>2.4.1</version>
</dependency>
Upvotes: 1
Views: 1193
Reputation: 18475
It is showing null
because your consumer never consumed and therefore never committed any offsets.
Have your consumer consuming messages from the assigned topic, commit them and then some values will show up from the committed
method.
Upvotes: 2