我正在学习kafka,并正在关注2.0.0的教程。我有一个针对消费者的示例代码
Properties properties = new Properties();
properties.setProperty(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers);
properties.setProperty(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class.getName());
properties.setProperty(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class.getName());
properties.setProperty(ConsumerConfig.GROUP_ID_CONFIG, groupId);
properties.setProperty(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");
//Create consumer
// KafkaConsumer<String,String> kafkaConsumer = new KafkaConsumer<String, String>(properties);
KafkaConsumer<String, String> consumer = new KafkaConsumer<String, String>(properties);
// subscribe consumer to our topic(s)
consumer.subscribe(Arrays.asList(topic));
//Poll on new Data
while(true){
ConsumerRecords<String, String> records =
consumer.poll(Duration.ofMillis(100));
for (ConsumerRecord<String, String> record : records){
_log.debug("Key: " + record.key() + ", Value: " + record.value());
_log.debug("Partition: " + record.partition() + ", Offset:" + record.offset());
}
}
此代码在2.0.0上有效,但是如果我将kafka版本更新为2.3.0或2.4.0,则记录将为空。 我已经把消息推送给生产者了。
我一直在浏览文档,但无法在此处找出需要更改的内容