Using high level consumer and assuming you already created an iterator:

while (msgCount < maxMessages && it.hasNext()) {
 bytes = it.next().message();
 eventList.add(bytes);
}

(See a complete example here:
https://github.com/apache/flume/blob/trunk/flume-ng-sources/flume-kafka-source/src/main/java/org/apache/flume/source/kafka/KafkaSource.java)

Gwen

On Thu, Sep 25, 2014 at 9:15 AM, pankaj ojha <pankajojh...@gmail.com> wrote:
> Hi,
>
> My requirement is to read a specific number of messages from kafka topic
> which contains data in json format and after reading number of messges, i
> need to write that in a file and then stop. How can I count number of
> messages read by my consumer code(either simpleconsumer or high level) ?
>
> Please help.
>
> --
> Thanks,
> Pankaj Ojha

Reply via email to