public static long getOffset(SimpleConsumer consumer, String topic, int partition, long whichTime) throws IOException { String errMsg = null; Exception lastEx = null; for (int i = 0; i < FETCH_RETRIES; i++) { TopicAndPartition topicAndPartition = new TopicAndPartition(topic, partition); try { long offset = consumer.earliestOrLatestOffset(topicAndPartition, whichTime, Request.DebuggingConsumerId()); return offset; } catch (RuntimeException e) { lastEx = e; errMsg = "Failed to getting offset for topic: " + topic + " partition: " + partition + " host: " + consumer.host(); LOG.warn(errMsg, e); try { Thread.sleep((long) (Math.random() * 3000)); } catch (InterruptedException ex) { LOG.warn("Unexpected interruption", ex); } } } throw new IOException(errMsg, lastEx); }
public static long getOffset(SimpleConsumer consumer, String topic, int partition, long whichTime) throws IOException { String errMsg = null; Exception lastEx = null; for (int i = 0; i < FETCH_RETRIES; i++) { TopicAndPartition topicAndPartition = new TopicAndPartition(topic, partition); try { long offset = consumer.earliestOrLatestOffset(topicAndPartition, whichTime, Request.DebuggingConsumerId()); return offset; } catch (RuntimeException e) { lastEx = e; errMsg = "Failed to getting offset for topic: " + topic + " partition: " + partition + " host: " + consumer.host(); LOG.warn(errMsg, e); try { Thread.sleep((long) (Math.random() * 3000)); } catch (InterruptedException ex) { LOG.warn("Unexpected interruption", ex); } } } throw new IOException(errMsg, lastEx); }
FetchRequest req = new FetchRequestBuilder() .clientId(FETCH_CLIENT_NAME) .replicaId(Request.DebuggingConsumerId()) // this consumerId enable reads from follower .maxWait(FETCH_MAX_WAIT_MS) .minBytes(ConsumerConfig.MinFetchBytes())
FetchRequest req = new FetchRequestBuilder() .clientId(FETCH_CLIENT_NAME) .replicaId(Request.DebuggingConsumerId()) // this consumerId enable reads from follower .maxWait(FETCH_MAX_WAIT_MS) .minBytes(ConsumerConfig.MinFetchBytes())