java 无法在 kafka 消费者下设置 'max.poll.records',其中 cons.poll 仍然返回分区下的所有记录

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/37413273/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 02:28:44  来源:igfitidea点击:

unable to set 'max.poll.records' under kafka consumer, where cons.poll still returns all records under partition

javaapache-kafkakafka-consumer-api

提问by usman

I have created multi thread consumerapp to work upon various partitions. Looking into various blogs i came to know about 'max.poll.records' property, in order to get control over the set of records from given topic, partition.(so it can quickly come out of Records loop and hence call cons.poll() to keep alive)

我创建了多线程消费者应用程序来处理各种分区。查看各种博客,我开始了解“max.poll.records”属性,以便控制来自给定主题和分区的记录集。(因此它可以快速退出 Records 循环并因此调用 cons.poll () 保持活力)

Problem is my processing logic takes time to process each record. upon starting Cons-2 both start to work on same partition as Cons-1 still did not went for re-balance (i.e. cons.poll() not happened yet).

问题是我的处理逻辑需要时间来处理每条记录。启动 Cons-2 后,两者都开始在同一个分区上工作,因为 Cons-1 仍然没有进行重新平衡(即 cons.poll() 尚未发生)。

Increasing consumers so they can re-balancethem selves, cons.poll() will not occur unless all records are processed.

增加消费者以便他们可以重新平衡自己,除非处理所有记录,否则 cons.poll() 不会发生。

I may not go for 'session.timeout.ms' as starting new consumer may also start working on same partition as of Cons-1.

我可能不会选择“session.timeout.ms”,因为开始新的消费者也可能开始在与 Cons-1 相同的分区上工作。

I have tried setting property using :

我尝试使用以下方法设置属性:

props.put("max.poll.records",1);
props.put("max.poll.records","1");

but neither changed the no. of records from poll.

但两者都没有改变。民意调查的记录。

I am using Apache Kafka 9 and Below API.

我正在使用 Apache Kafka 9 及以下 API。

<dependency>
    <groupId>org.apache.servicemix.bundles</groupId>
    <artifactId>org.apache.servicemix.bundles.kafka-clients</artifactId>
    <version>0.9.0.1_1</version>
</dependency>

回答by Kamal Chandraprakash

max.poll.recordsproperty released in Kafka-0.10.0. It's not available in Kafka 0.9.0.1 version. See KAFKA-3007 task in the releasenotes.

max.poll.records在 Kafka-0.10.0 中发布的属性。它在 Kafka 0.9.0.1 版本中不可用。请参阅发行说明中的 KAFKA-3007 任务。

If your processing of records took much time, the below link might be helpful.

如果您处理记录需要很长时间,下面的链接可能会有所帮助。

AdvancedConsumer.java

高级消费者.java