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
- latest: automatically reset the offset to the latest offset
- none: throw exception to the consumer if no previous offset is found for the consumer's group
- anything else: throw exception to the consumer.
翻译:
当Kafka中没有初始偏移或如果当前偏移在服务器上不再存在时(例如,因为该数据已被删除),该怎么办:
- 最早:自动将偏移重置为最早的偏移
- 最新:自动将偏移重置为最新偏移
- none:如果没有为消费者组找到以前的偏移,则向消费者抛出异常
- 任何其他:抛出异常到消费者。
“auto.offset.reset”的值只能是:[latest, earliest, none]中的一个,默认是"latest"
代码示例:
from kafka import KafkaConsumer
consumer=KafkaConsumer('test',auto_offset_reset='earliest',bootstrap_servers=['172.21.10.136:9092'])
for message in consumer:
print ("%s:%d:%d: key=%s value=%s" % (message.topic, message.partition,message.offset, message.key,message.value))
本文介绍了Kafka中auto_offset_reset配置的作用,当消费者找不到初始偏移量或数据已删除时,可以选择自动重置到最早的偏移量、最新的偏移量,或者抛出异常。通过代码示例展示了如何设置此参数。
235

被折叠的 条评论
为什么被折叠?



