简体   繁体   English

卡夫卡简单的消费者间歇性地丢失了消息

[英]Kafka simple consumer intermittently missing messages

I have a Kafka application from where I have been consuming messages using kafka-console-consumer.sh as following: 我有一个Kafka应用程序,我使用kafka-console-consumer.sh消费消息,如下所示:

$./kafka-console-consumer.sh --zookeeper zookeeperhost:2181 --topic myTopic

which gives all the messages which I write to Kafka broker through a Kafka consumer without any miss. 它提供了我通过Kafka消费者写给Kafka经纪人的所有消息,没有任何遗漏。

Recently I deployed the application in a different environment where zookeeperhost is not accessible (due to some reason). 最近我在不能访问zookeeperhost的不同环境中部署了应用程序(由于某种原因)。 So I am using kafka-simple-consumer-shell.sh instead as below: 所以我使用的是kafka-simple-consumer-shell.sh,如下所示:

$./kafka-simple-consumer-shell.sh --broker-list brokerhost:9092 --topic myTopic --partition 0 --max-messages 1

But with this I see few messages (around 2-4 in 5000) go missed. 但是有了这个,我看到很少有消息(大约2-4个中的2-4个)被遗漏。 Could someone please explain how kafka-simple-consumer-shell.sh reads messages. 有人可以解释kafka-simple-consumer-shell.sh如何读取消息。

I am doubting that probably some messages are going to some different partition and as I am just reading from partition 0 so I am not getting all the messages every time. 我怀疑可能有些消息会转到某个不同的分区,因为我只是从分区0读取所以我不是每次都收到所有消息。 But I do not know how to check how many partitions are there? 但我不知道如何检查有多少分区? and what are the ids for other partitions? 什么是其他分区的ID? I tried with 1 but it does not work. 我试过1但它不起作用。

Could someone please help. 请有人帮忙。

kafka-simple-consumer.sh simply creates a consumer that reads messages from one partition. kafka-simple-consumer.sh只是创建一个从一个分区读取消息的使用者。 So your command simply reads a single message in partition 0 of myTopic from brokerhost:9092 . 因此,您的命令只是从brokerhost:9092读取brokerhost:9092 partition 0 of myTopic的单个消息。 If partition 1 is not in the same broker, it will not work as what you did. 如果分区1不在同一代理中,则它将不像您所做的那样工作。 (For more information, check Code from GitHub ) (有关更多信息,请查看GitHub中的代码

If you can access to the Zookeeper host, you can simply check how partitions are distributed in a cluster with 如果您可以访问Zookeeper主机,则只需检查分区在群集中的分布方式

bin/kafka-topics.sh --describe --zookeeper zookeeperhost:2181 --topic myTopic

but if you can't access to the Zookeeper host, there are two ways as I can think of. 但如果您无法访问Zookeeper主机,我可以通过两种方式来考虑。

  1. Provide a list having all brokers as a parameter and try partition numbers from 0 to N. You can provide multiple brokers to --broker-list in a format of broker1:port2,broker2:port2,broker3:port3 . 提供一个包含所有代理作为参数的列表,并尝试从0到N的分区号。您可以以broker1:port2,broker2:port2,broker3:port3的格式提供多个代理到--broker-list Then you can figure out how many partitions exist in the entire cluster, but still you don't know which broker has which partitions. 然后,您可以确定整个群集中存在多少个分区,但您仍然不知道哪个代理具有哪些分区。
  2. Manually check a log directory of each broker. 手动检查每个代理的日志目录。 Check /tmp/kafka-logs (if you are using a default log directory). 检查/tmp/kafka-logs (如果使用的是默认日志目录)。 You will find directories like myTopic-0 , myTopic-1 , ... which are in a format of topic-partition# . 您将找到myTopic-0myTopic-1 ,其格式为topic-partition# You can check which broker has which partitions manually with this. 您可以使用此方法检查哪个代理手动具有哪些分区。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM