Ansh-me2
Ansh-me2

Reputation: 45

get only one record from kafka offset

I know that the data can be read from kafka from a particular offset by using --offset in kafka-console-consumer, but this gives the records from that particular offset till the current offset. How can I limit it to one record only.

Upvotes: 2

Views: 1403

Answers (1)

pedromss
pedromss

Reputation: 2453

If you use the --help on the kafka-console-consumer command you can see:

--max-messages <Integer: num_messages>   The maximum number of messages to      
                                           consume before exiting. If not set,  
                                           consumption is continual.            
--offset <String: consume offset>        The offset id to consume from (a non-  
                                           negative number), or 'earliest'      
                                           which means from beginning, or       
                                           'latest' which means from end        
                                           (default: latest)       

--max-messages set to 1 is what you want

Upvotes: 5

Related Questions