Created
November 5, 2015 21:17
-
-
Save hisplan/702228c82752466af360 to your computer and use it in GitHub Desktop.
Python Kafka Consumer
This file contains 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
from kafka import KafkaConsumer | |
# To consume messages | |
consumer = KafkaConsumer('my-topic', | |
group_id='my_group', | |
bootstrap_servers=['localhost:9092']) | |
for message in consumer: | |
# message value is raw byte string -- decode if necessary! | |
# e.g., for unicode: `message.value.decode('utf-8')` | |
print("%s:%d:%d: key=%s value=%s" % (message.topic, message.partition, | |
message.offset, message.key, | |
message.value)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment