當前位置: 首頁>>代碼示例>>Java>>正文


Java ConsumerRecords.empty方法代碼示例

本文整理匯總了Java中org.apache.kafka.clients.consumer.ConsumerRecords.empty方法的典型用法代碼示例。如果您正苦於以下問題:Java ConsumerRecords.empty方法的具體用法?Java ConsumerRecords.empty怎麽用?Java ConsumerRecords.empty使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.kafka.clients.consumer.ConsumerRecords的用法示例。


在下文中一共展示了ConsumerRecords.empty方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testReportingMetrics

import org.apache.kafka.clients.consumer.ConsumerRecords; //導入方法依賴的package包/類
@Test
public void testReportingMetrics() {
  Properties props = new Properties();
  props.setProperty(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers());
  props.setProperty(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class.getName());
  props.setProperty(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, MetricSerde.class.getName());
  props.setProperty(ConsumerConfig.GROUP_ID_CONFIG, "testReportingMetrics");
  props.setProperty(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");
  setSecurityConfigs(props, "consumer");
  Consumer<String, CruiseControlMetric> consumer = new KafkaConsumer<>(props);

  ConsumerRecords<String, CruiseControlMetric> records = ConsumerRecords.empty();
  consumer.subscribe(Collections.singletonList(TOPIC));
  long startMs = System.currentTimeMillis();
  Set<Integer> metricTypes = new HashSet<>();
  while (metricTypes.size() < 16 && System.currentTimeMillis() < startMs + 15000) {
    records = consumer.poll(10);
    for (ConsumerRecord<String, CruiseControlMetric> record : records) {
      metricTypes.add((int) record.value().metricType().id());
    }
  }
  HashSet<Integer> expectedMetricTypes = new HashSet<>(Arrays.asList((int) ALL_TOPIC_BYTES_IN.id(),
                                                                     (int) ALL_TOPIC_BYTES_OUT.id(),
                                                                     (int) TOPIC_BYTES_IN.id(),
                                                                     (int) TOPIC_BYTES_OUT.id(),
                                                                     (int) PARTITION_SIZE.id(),
                                                                     (int) BROKER_CPU_UTIL.id(),
                                                                     (int) ALL_TOPIC_PRODUCE_REQUEST_RATE.id(),
                                                                     (int) ALL_TOPIC_FETCH_REQUEST_RATE.id(),
                                                                     (int) ALL_TOPIC_MESSAGES_IN_PER_SEC.id(),
                                                                     (int) TOPIC_PRODUCE_REQUEST_RATE.id(),
                                                                     (int) TOPIC_FETCH_REQUEST_RATE.id(),
                                                                     (int) TOPIC_MESSAGES_IN_PER_SEC.id(),
                                                                     (int) BROKER_PRODUCE_REQUEST_RATE.id(),
                                                                     (int) BROKER_CONSUMER_FETCH_REQUEST_RATE.id(),
                                                                     (int) BROKER_FOLLOWER_FETCH_REQUEST_RATE.id(),
                                                                     (int) BROKER_REQUEST_HANDLER_AVG_IDLE_PERCENT.id()));
  assertEquals("Expected to see " + expectedMetricTypes + ", but only see " + metricTypes, metricTypes, expectedMetricTypes);
}
 
開發者ID:linkedin,項目名稱:cruise-control,代碼行數:40,代碼來源:CruiseControlMetricsReporterTest.java

示例2: poll

import org.apache.kafka.clients.consumer.ConsumerRecords; //導入方法依賴的package包/類
@Override
public ConsumerRecords<K, V> poll(long timeout) {
    if (!hasRecords.get()) {
        return ConsumerRecords.empty();
    }
    hasRecords.set(false);
    return super.poll(timeout);
}
 
開發者ID:epam,項目名稱:Lagerta,代碼行數:9,代碼來源:ProxyMockConsumer.java

示例3: poll

import org.apache.kafka.clients.consumer.ConsumerRecords; //導入方法依賴的package包/類
@Override public ConsumerRecords<K, V> poll(long timeout) {
    if (!hasRecords.get()) {
        return ConsumerRecords.empty();
    }
    hasRecords.set(false);
    return super.poll(timeout);
}
 
開發者ID:epam,項目名稱:Lagerta,代碼行數:8,代碼來源:ProxyMockConsumer.java

示例4: ConsumerAndRecords

import org.apache.kafka.clients.consumer.ConsumerRecords; //導入方法依賴的package包/類
ConsumerAndRecords(KafkaConsumer<String, byte[]> consumer, String uuid) {
  this.consumer = consumer;
  this.uuid = uuid;
  this.records = ConsumerRecords.empty();
  this.recordIterator = records.iterator();
}
 
開發者ID:moueimei,項目名稱:flume-release-1.7.0,代碼行數:7,代碼來源:KafkaChannel.java


注:本文中的org.apache.kafka.clients.consumer.ConsumerRecords.empty方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。