基于时间戳的kafka主题重播
kafka_replayer的Python项目详细描述
kafka_replayer是一个库,它帮助消费来自kafka主题的消息的时间范围。而 标准的kafka使用者api允许使用 作为重播抽象的偏移量是很麻烦的,而且可能容易出错。这个图书馆 从时间戳到偏移的转换是透明的。
这个库是用python编写的,它利用kafka-python的使用者轮询kafka以获取消息。
安装
$ pip install python-kafka-replayer
使用
importjsonimportkafka_replayerdes_fn=lambdax:json.loads(x)ifxelseNonereplayer=kafka_replayer.KafkaReplayer('my-topic',bootstrap_servers=['localhost:9092'],key_deserializer=des_fn,value_deserializer=des_fn)# Replay all records between the start and end millis timestampsforrecordinreplayer.replay(1469467314341,1469467907549):printrecord
许可证
见LICENSE。