Giu*_*ppe 2 python consumer apache-kafka pykafka
在我的 kafka 集群单分区主题中,我有一个简单的使用者处理所有传入的消息,如果处理的数据出错,我想以相同的顺序重新处理来自某个偏移量(不是开始)的所有消息,以修复不一致并保持来自 kafka 的原始有序消息序列。
有没有办法用 Pykafka 做到这一点?我不明白
你需要打电话reset_offsets()。例如:
consumer = topic.get_simple_consumer(consumer_group="example")
partition_offset_pairs = [(p, get_offset_for_partition(p)) for p in consumer.partitions.itervalues()]
# because we passed in a consumer_group the new offsets will be saved in Kafka
consumer.reset_offsets(partition_offsets=partition_offset_pairs)
(get_offset_for_partition()您定义的函数在哪里)。或者对于单分区主题:
# read from offset 123456
consumer = topic.get_simple_consumer()
partition = topic.partitions[0]
consumer.reset_offsets([(partition, 123456)])
同样的reset_offsets()方法也可用于BalancedConsumer&ManagedBalanceConsumer类。
请注意,作为 Kafka 设计的一部分,仅保证每个主题分区的消息按顺序独立。
| 归档时间: | 
 | 
| 查看次数: | 853 次 | 
| 最近记录: |