Created
January 25, 2017 14:21
-
-
Save sjednac/74c569e0cfd16e0e331d5392f21e71bf to your computer and use it in GitHub Desktop.
A Kafka consumer for listing available schema versions
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
# | |
# A Kafka consumer, that will print schema version information for | |
# all available subjects. | |
# | |
# Use the RESTful API to query SchemaRegistry directly. For example: | |
# curl http://schema-registry:8081/subjects/{subject}/versions | |
# | |
from kafka import KafkaConsumer | |
from random import randint | |
import json | |
def decode_message (msg): | |
if msg: | |
return json.loads(msg.decode('utf8')) | |
else: | |
return None | |
consumer = KafkaConsumer(bootstrap_servers='kafka:9092', group_id='schema-version-list-'+str(randint(0,1000)), request_timeout_ms=5000, session_timeout_ms=10000, auto_offset_reset='earliest', value_deserializer=decode_message) | |
consumer.subscribe(['_schemas']) | |
for msg in consumer: | |
key = msg.key | |
val = msg.value | |
print "subject=", val['subject'], " version=", val['version'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment