kafka get last offset of topic python

Solutions on MaxInterview for kafka get last offset of topic python by the best coders in the world

showing results for - "kafka get last offset of topic python"
Luisa
15 Mar 2018
1from kafka import SimpleClient
2from kafka.protocol.offset import OffsetRequest, OffsetResetStrategy
3from kafka.common import OffsetRequestPayload
4
5client = SimpleClient(brokers)
6
7partitions = client.topic_partitions[topic]
8offset_requests = [OffsetRequestPayload(topic, p, -1, 1) for p in partitions.keys()]
9
10offsets_responses = client.send_offset_request(offset_requests)
11
12for r in offsets_responses:
13    print "partition = %s, offset = %s"%(r.partition, r.offsets[0])