for (String topic : topics) {
for (int i = 0; i < num_partitions; i++) {
TopicAndPartition topicAndPartition = new TopicAndPartition(
topic, i);
SimpleConsumer consumer = mKafkaClient
.createConsumer(new TopicPartition(topic, i));
Map<TopicAndPartition, PartitionOffsetRequestInfo> requestInfo = new HashMap<TopicAndPartition, PartitionOffsetRequestInfo>();
requestInfo.put(topicAndPartition,
new PartitionOffsetRequestInfo(-1, 1));
kafka.javaapi.OffsetRequest request = new kafka.javaapi.OffsetRequest(
requestInfo, kafka.api.OffsetRequest.CurrentVersion(),
"TestPerformance");
OffsetResponse response = consumer.getOffsetsBefore(request);
if (response.hasError()) {
System.out
.println("Error fetching data Offset Data the Broker. Reason: "
+ response.errorCode(topic, i));
return null;
}
long[] offsets = response.offsets(topic, i);
System.out.println("Topic: " + topic + " partition: " + i
+ " offset: " + offsets[0]);
lastOffsets.put(new TopicPartition(topic, i), offsets[0]);
}
}
return lastOffsets;
}