【发布时间】:2017-09-16 01:32:47
【问题描述】:
如果我有一个enable.auto.commit=false 并且我调用consumer.poll() 之后没有调用consumer.commitAsync(),为什么consumer.poll() 返回
下次调用时有新记录吗?
由于我没有提交我的偏移量,我希望poll() 会返回最新的偏移量,这应该是相同的记录。
我之所以这么问,是因为我试图在处理过程中处理失败场景。我希望在不提交偏移量的情况下,poll() 会再次返回相同的记录,以便我可以再次重新处理那些失败的记录。
public class MyConsumer implements Runnable {
@Override
public void run() {
while (true) {
ConsumerRecords<String, LogLine> records = consumer.poll(Long.MAX_VALUE);
for (ConsumerRecord record : records) {
try {
//process record
consumer.commitAsync();
} catch (Exception e) {
}
/**
If exception happens above, I was expecting poll to return new records so I can re-process the record that caused the exception.
**/
}
}
}
}
【问题讨论】:
标签: apache-kafka kafka-consumer-api