kafka.api.Request Java Examples
The following examples show how to use
kafka.api.Request.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: IntegrationTestUtils.java From ksql-fork-with-deep-learning-function with Apache License 2.0 | 6 votes |
public static void waitUntilMetadataIsPropagated(final List<KafkaServer> servers, final String topic, final int partition, final long timeout) throws InterruptedException { TestUtils.waitForCondition(new TestCondition() { @Override public boolean conditionMet() { for (final KafkaServer server : servers) { final MetadataCache metadataCache = server.apis().metadataCache(); final Option<UpdateMetadataRequest.PartitionState> partitionInfo = metadataCache.getPartitionInfo(topic, partition); if (partitionInfo.isEmpty()) { return false; } final UpdateMetadataRequest.PartitionState metadataPartitionState = partitionInfo.get(); if (!Request.isValidBrokerId(metadataPartitionState.basePartitionState.leader)) { return false; } } return true; } }, timeout, "metadata for topic=" + topic + " partition=" + partition + " not propagated to all brokers"); }
Example #2
Source File: OperatorUtil.java From doctorkafka with Apache License 2.0 | 6 votes |
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); }
Example #3
Source File: KafkaInfos.java From DCMonitor with MIT License | 5 votes |
private long getTopicLogSize(String topic, int pid) { Option<Object> o = ZkUtils.getLeaderForPartition(zkClient, topic, pid); if (o.isEmpty() || o.get() == null) { log.error("No broker for partition %s - %s", topic, pid); return 0; } Integer leaderId = Int.unbox(o.get()); SimpleConsumer consumer = consumerMap.get(leaderId); if (consumer == null) { consumer = createSimpleConsumer(leaderId); } // createSimpleConsumer may fail. if (consumer == null) { return 0; } consumerMap.put(leaderId, consumer); TopicAndPartition topicAndPartition = new TopicAndPartition(topic, pid); PartitionOffsetRequestInfo requestInfo = new PartitionOffsetRequestInfo(OffsetRequest.LatestTime(), 1); OffsetRequest request = new OffsetRequest( new Map1<TopicAndPartition, PartitionOffsetRequestInfo>(topicAndPartition, requestInfo), 0, Request.OrdinaryConsumerId() ); OffsetResponse response = consumer.getOffsetsBefore(request); PartitionOffsetsResponse offsetsResponse = response.partitionErrorAndOffsets().get(topicAndPartition).get(); return scala.Long.unbox(offsetsResponse.offsets().head()); }