当前位置: 首页>>代码示例>>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;未经允许,请勿转载。