今天在写kafka的java api例子时候,遇到一个问题,比如我创建了一个test主题,往里面写了1,2,3,4,5条消息,在这个时候,我用一个新的group启动了一个消费者,发现该消费者只能读到5以后的消息,而1到5的消息是读不到的,于是感到疑惑,就去官网上找了一下,看到这这样一个配置项“auto.offset.reset”,该配置项的描述如下:
What to do when there is no initial offset in Kafka or if the current offset does not exist any more on the server (e.g. because that data has been deleted):
- earliest: automatically reset the offset to the earliest offset