Re: Read a specific number of messages using kafka

2014-09-26 Thread Joel Koshy
You can use any offset you like to fetch (provided it is present on the broker). Since the client-side FetchRequest and the server-side Log API don't support reading a specific _number_ of messages you will need to specify the bytes (size) to read. You can then extract as many messages as you like

Re: Read a specific number of messages using kafka

2014-09-25 Thread Sharninder
Slight off-topic, but is it also possible to replay a specific number of messages? For example, using the simple consumer, can I go back/reset the offset so that I always go read the last 10 messages assuming the size of each individual message could be different. All I found in the simple consumer

Re: Read a specific number of messages using kafka

2014-09-25 Thread pankaj ojha
Thank You. I will try this out. On Thu, Sep 25, 2014 at 10:01 PM, Gwen Shapira wrote: > 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 ex

Re: Read a specific number of messages using kafka

2014-09-25 Thread Gwen Shapira
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/jav

Read a specific number of messages using kafka

2014-09-25 Thread pankaj ojha
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) ? Ple