本文整理匯總了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();
}