本文整理汇总了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);
}
示例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);
}
示例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);
}
示例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();
}