擅长:python、mysql、java
<p><code>linkedin/kafka-tools</code>有一个函数<code>get_offsets_for_group()</code>,用于获取组偏移量。它可以传递一个组名和主题名,或者只传递一个组名来检索该组的所有主题的已提交偏移量。在</p>
<pre><code>from kafka.tools.client import Client
group='mygroup'
client=Client(broker_list='localhost:9029')
client.connect()
offsets=client.get_offsets_for_group(group)
for topic in offsets:
for partition_offset in offsets[topic].partitions:
print("group: {0} - topic: {1} - partition: {2}".format(group,topic,partition_offset))
</code></pre>