apache-kafka - 卡夫卡消费者从一开始就不消费

标签 apache-kafka kafka-consumer-api kafka-producer-api kafka-topic

我在本地机器上安装了 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
  • 使用新的消费者 ID 将从起始点开始消费

  • kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic edu-topic --group new-edu-service --from-beginning
  • 您还可以使用偏移量来消费来自分区
  • 的下 N 条消息。

    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/

    相关文章:

    c# - 如何使用 Confluent.Kafka .Net Client 创建 Kafka Topic

    java - Zookeeper 属性仍然是 Kafka 消费者的一个要求吗?

    apache-kafka - 即使Apache Kafka配置文件已经有了,为什么我们还需要提及Zookeeper的细节?

    spring-boot - Spring Boot 和 Kafka : Failed to send SSL Close message

    apache-kafka - 在kafka中发送同步消息?

    java - Spring Boot 关闭前的 Kafka 手动确认

    apache-kafka - 卡夫卡 : how to remove broker from Replica Set

    java - Spring Kafka 与 Confluence Kafka Avro 反序列化器

    apache-kafka - 向 Kafka 发送消息时是否需要 key ?

    apache-kafka - 在模式注册表中,消费者的模式可能与生产者的模式不同,这实际上意味着什么