Skip to content

Instantly share code, notes, and snippets.

@hisplan
Created November 5, 2015 21:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save hisplan/702228c82752466af360 to your computer and use it in GitHub Desktop.
Save hisplan/702228c82752466af360 to your computer and use it in GitHub Desktop.
Python Kafka Consumer
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