Kafka Consumer seektoBeginning

孤人 提交于 2019-12-24 03:07:58

问题


I did not use a partition to publish to Kafka topic. ProducerRecord(String topic, K key, V value)

In the consumer, I would like to go to the beginning. seekToBeginning(Collection partitions)

Is it possible to seek to beginning without using a partition? Does Kafka assign a default partition?

https://kafka.apache.org/0102/javadoc/org/apache/kafka/clients/producer/ProducerRecord.html https://kafka.apache.org/0102/javadoc/org/apache/kafka/clients/consumer/KafkaConsumer.html


回答1:


When producing, if you don't explicitely specify a partition, the producer will pick one automatically from your topic.

In your consumer, if your are subscribed to your topic, you can seek to the start of all the partitions your consumer is currently assigned to using:

consumer.seekToBeginning(consumer.assignment())


来源:https://stackoverflow.com/questions/49723182/kafka-consumer-seektobeginning

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!