}
private void findLeader() {
closeConsumer();
PartitionMetadata metadata = fetchPartitonMetadata();
if (metadata == null) {
String message = String.format("Could not find leader for topic %s, partition %d",
topic, partition);
LOG.error(message);
throw new RuntimeException(message);
}
if (metadata.leader() == null) {
LOG.warn("Can't find leader for topic {} and partition {} with brokers {}.",
topic, partition, replicaBrokers, ErrorMapping.exceptionFor(metadata.errorCode()));
throw new RuntimeException(ErrorMapping.exceptionFor(metadata.errorCode()));
}
consumer = new SimpleConsumer(metadata.leader().host(), metadata.leader().port(), TIMEOUT_MS, BUFFER_SIZE_BYTES,
clientName);
saveReplicaBrokers(metadata);
}