Kafka消费者从一开始就没有消费

问题描述 投票:0回答:3

我在本地计算机上安装了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

但是,它显示的是新添加的消息。

我在这里做什么错?有什么帮助吗?

apache-kafka kafka-consumer-api kafka-producer-api kafka-topic
3个回答
0
投票

标志

--from-begining

将在第一次启动/创建GroupConsumer时影响其行为,或者存储的(最后一次消耗的)偏移量过期(或者可能在您尝试重置存储的偏移量时。)>]

否则,GroupConsumer将仅在存储的(最后提交的)偏移量处继续

请考虑从手册中获取更多信息。


0
投票

因为您使用的是旧的消费群体。 --from-beginning仅适用于尚未在Kafka群集上记录其组名称的新使用者组。

要从头开始再次消费,您可以:


0
投票

Kafka消费者第一次使用-from-beginning

© www.soinside.com 2019 - 2024. All rights reserved.