我在本地机器上安装了 Kafka,并启动了 zookeeper 和一个代理服务器。
现在我有一个具有以下描述的主题:
~/Documents/backups/kafka_2.12-2.2.0/data/kafka$ kafka-topics.sh --zookeeper 127.0.0.1:2181 --topic edu-topic --describe
Topic:edu-topic PartitionCount:3 ReplicationFactor:1 Configs:
Topic: edu-topic Partition: 0 Leader: 0 Replicas: 0 Isr: 0
Topic: edu-topic Partition: 1 Leader: 0 Replicas: 0 Isr: 0
Topic: edu-topic Partition: 2 Leader: 0 Replicas: 0 Isr: 0
我有一个生产者在消费者启动之前已经产生了一些消息,如下所示:
~/Documents/backups/kafka_2.12-2.2.0/data/kafka$ kafka-console-producer.sh --broker-list 127.0.0.1:9092 --topic edu-topic
>book
>pen
>pencil
>marker
>
当我使用 --from-beginning 选项启动消费者时,它不会显示生产者产生的所有消息:
~/Documents/backups/kafka_2.12-2.2.0/data/kafka$ kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic edu-topic --group edu-service --from-beginning
但是,它显示的是新添加的消息。
我在这里做什么错了?有什么帮助吗?
最佳答案
--from-beginning: If the consumer does not already have an established offset to consume from, start with the earliest message present in the log rather than the latest message.
Kafka 消费者使用 --从头开始如果你第一次重试,我怀疑你做了,它会从它离开的地方开始。您可以使用以下任何选项再次使用该消息
kafka-streams-application-reset.sh --application-id edu-service
--input-topics edu-topic --bootstrap-servers localhost:9092 --zookeeper 127.0.0.1:2181
然后从头重试
kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic edu-topic --group edu-service --from-beginning
kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic edu-topic --group new-edu-service --from-beginning
kafka-console-consumer.sh --bootstrap-server localhost:9092 --offset 0 --partition 0 --topic edu-topic
--offset <String: consume offset> : The offset id to consume from (a non- negative number), or 'earliest' which means from beginning, or 'latest' which means from end (default: latest)
--partition <Integer: partition> : The partition to consume from Consumption starts from the end of the partition unless '--offset' is specified.
关于apache-kafka - 卡夫卡消费者从一开始就不消费,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58928487/