Sat
Sat

Reputation: 4158

How to get consumer offset value of kafka

I have producer which is sending messages to a topic continuously.

Suppose my consumer consumed 1 to 10 messages, before consuming the 11th message it was crashed , when it get back producer produced 100 messages let say now messages are 110, I know that When a consumer joins a consumer group it will fetch the last committed offset so it will restart to read from 11 but I want to print these offset values in log using java and making sure that it wont miss a message

Also how can we get the topic wise TTL in kafka

Upvotes: 1

Views: 3313

Answers (1)

Abhimanyu
Abhimanyu

Reputation: 2740

From ConsumerRecord you can get all the metadata corresponding to a topic

kafkaConsumer.subscribe(topicNameList , new HandleRebalance())
            String kafkaMessages = null
            try{
                while(true){
                   ConsumerRecords kafkaRecords
                   kafkaRecords = kafkaConsumer.poll(100)
                     for(ConsumerRecord record: kafkaRecords){
                       partition = record.partition()
                       offset = record.offset()
                       topicName = record.topic()
                         Object message = record.value()
                       }

Upvotes: 2

Related Questions