简体   繁体   English

Kafka消费者停止消费消息

[英]Kafka consumer stops consuming messages

I have a simple kafka setup.我有一个简单的 kafka 设置。 A producer is producing messages to a single partition with a single topic at a high rate.生产者正在以高速率向具有单个主题的单个分区生成消息。 A single consumer is consuming messages from this partition.单个消费者正在使用来自该分区的消息。 During this process, the consumer may pause processing messages several times.在此过程中,消费者可能会多次暂停处理消息。 The pause can last a couple of minutes.暂停可能会持续几分钟。 After the producer stops producing messages, all messages queued up will be processed by the consumer.生产者停止生产消息后,所有排队的消息都会被消费者处理。 It appears that messages produced by the producer are not being seen immediately by the consumer.似乎消费者没有立即看到生产者产生的消息。 I am using kafka 0.10.1.0.我正在使用 kafka 0.10.1.0。 What can be happening here?这里会发生什么? Here is the section of code that consumes the message:这是使用消息的代码部分:

            while (true)
            {
                try
                {
                    ConsumerRecords<String, byte[]> records = consumer.poll(100);
                    for (final ConsumerRecord<String, byte[]> record : records)
                    {
                        serviceThread.submit(() ->
                        {
                            externalConsumer.accept(record);
                        });
                    }
                    consumer.commitAsync();
                } catch (org.apache.kafka.common.errors.WakeupException e)
                {
                }
            }

where consumer is a KafkaConsumer with auto commit disabled, max poll record of 100, and session timeout of 30000. serviceThread is an ExecutorService.其中消费者是禁用自动提交的 KafkaConsumer,最大轮询记录为 100,会话超时为 30000。 serviceThread 是一个 ExecutorService。

The producer just involves the KafkaProducer.send call to send a ProducerRecord.生产者只涉及 KafkaProducer.send 调用以发送 ProducerRecord。

All configurations on the broker are left as kafka defaults.代理上的所有配置都保留为 kafka 默认值。

I am also using kafka-consumer-groups.sh to check what is happening when consumer is not consuming the message.我还使用 kafka-consumer-groups.sh 来检查消费者不消费消息时发生的情况。 But when this happens, the kafka-consumer-groups.sh will be hanging there also, not able to get information back.但是当这种情况发生时,kafka-consumer-groups.sh 也会挂在那里,无法取回信息。 Sometimes it triggers the consumer re-balance.有时它会触发消费者重新平衡。 But not always.但不总是。

For those who can find this helpful.对于那些发现这有帮助的人。 I've encountered this problem (when kafka silently supposedly stops consuming) often enough and every single time it wasn't actually problem with Kafka.我经常遇到这个问题(当 kafka 应该默默地停止消费时),而且每次它实际上都不是 Kafka 的问题。

Usually it is some long-running or hanged silent process that keeps Kafka from committing the offset.通常是一些长时间运行或挂起的静默进程阻止 Kafka 提交偏移量。 For example a DB client trying to connect to the DB.例如,尝试连接到数据库的数据库客户端。 If you wait for long enough (eg 15 minutes for SQLAlchemy and Postgres), you will see a exception will be printed to the STDOUT, saying something like connection timed out .如果您等待的时间足够长(例如 SQLAlchemy 和 Postgres 为 15 分钟),您将看到一个异常将打印到 STDOUT,说诸如connection timed out

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

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