FetchRequest req = new FetchRequestBuilder()
.clientId(clientName)
.addFetch(topic, partition, fetchOffset, BUFFER_SIZE_BYTES)
.maxWait(fetchTimeoutMs)
.build();
FetchResponse fetchResponse = consumer.fetch(req);
if (fetchResponse.hasError()) {
errorCode = fetchResponse.errorCode(topic, partition);
LOG.warn(
String.format("Error fetching data from broker %s:%d for topic %s, partition %d. Error code: %d",
consumer.host(), consumer.port(), topic, partition, errorCode));
if (errorCode == ErrorMapping.OffsetOutOfRangeCode()) {
throw new OffsetOutOfRangeException(
String.format("Requested offset %d is out of range for topic %s partition %d",
fetchOffset, topic, partition));
}
findLeader();
continue;
}
return fetchResponse.messageSet(topic, partition);
}
String message = String.format("Error fetching data from broker %s:%d for topic %s, partition %d. Error code: %d",
consumer.host(), consumer.port(), topic, partition, errorCode);
LOG.error(message);
throw new RuntimeException(message);