java kafka 消费者轮询超时
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/41030854/
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
kafka consumer polling timeout
提问by john
I am working with Kafka and trying to consume data from it. From the below line, I can poll the data from Kafka.
我正在使用 Kafka 并尝试使用它的数据。从下面这行,我可以轮询来自 Kafka 的数据。
while (true) {
ConsumerRecords<byte[], <byte[]> records = consumer.poll(Long.MAX_VALUE);
for (ConsumerRecord<byte[], <byte[]> record : records) {
// retrieve data
}
}
My question is what is the benefit I am getting by providing Long.MAX_VALUE
as the timeout as compared to if I provide 200
as the timeout. What is the best practice for the system that will be running production.
我的问题是,与提供Long.MAX_VALUE
超时相比,提供超时有什么好处200
。将运行生产的系统的最佳实践是什么?
Can anyone explain me the difference of high timeout vs low timeout and which should be use in production system?
任何人都可以向我解释高超时与低超时的区别以及应该在生产系统中使用的区别吗?
采纳答案by amethystic
Setting MAX_VALUE is sort of a synchronous message consuming, waiting forever until we got something returned back from the poll, while setting to a lower value gives you a chance that you can decide to do something else other than awaiting. Which should be used depends on your actual scenario.
设置 MAX_VALUE 是一种同步消息消耗,永远等待,直到我们从轮询返回一些东西,而设置为较低的值让您有机会决定做其他事情而不是等待。应该使用哪个取决于您的实际场景。