1.Java Client Consumer 实现 "--from-beginning":
KafkaConsumer JavaDoc 的"Controlling The Consumer's Position"章节中提到,使用" seekToBeginning(Collection)
" 可以实现"--from-beginning"的功能,但是却没有告诉我们,这个方法如何调用.如果在"subscribe"之后,立刻调用"seekToBeginning"会提示"No current assignment for partition". 正确的调用姿势应该是在调用"subscribe"时,填入第2个 ConsumerRebalanceListener listener", 该参数在subscribe成功后回调.如:
consumer.subscribe(Arrays.asList(topic), new ConsumerRebalanceListener() {
@Override
public void onPartitionsRevoked(Collection partitions) {
}
@Override
public void onPartitionsAssigned(Collection partitions) {
consumer.seekToBeginning(partitions);
}
});