Last active
December 12, 2015 05:28
-
-
Save jibs/4722063 to your computer and use it in GitHub Desktop.
Kafka zookeeper cleanup script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
from kazoo.client import KazooClient | |
""" | |
Simple python script to clean up zookeeper consumer offsets after a errant kafka consumer. Only tested on Kafka 0.7. | |
For details on Kazoo: http://kazoo.readthedocs.org/en/latest/index.html | |
MIT License. | |
""" | |
def main(zkconn_str, group_id): | |
kc = KazooClient(zkconn_str) | |
kc.start() | |
assert(kc.connected) | |
node = '/consumers/%s' % group_id | |
print('Deleting consumer zk node (%s)' % node) | |
ans = raw_input('Confirm by retyping consumer-group: ') | |
if ans != group_id: | |
sys.exit('Consumer group mismatch') | |
kc.delete(node, recursive=True) | |
print('Done. Exiting.') | |
if __name__ == '__main__': | |
if len(sys.argv) < 3: | |
sys.exit('Usage: [ZK-CONNECT-STRING] [KAFKA-CONSUMER-GROUP-ID]') | |
main(sys.argv[1], sys.argv[2]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment