gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 05:01:18 24 4
gpt4 key购买 nike

我在本地机器上安装了 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 messagepresent 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/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com