Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Kafka Python client code
from kafka import KafkaProducer
producer = KafkaProducer(bootstrap_servers=['localhost:19092'])
data = bytes('hello', encoding='utf-8')
producer.send('test', value=data)
from kafka import KafkaConsumer
consumer = KafkaConsumer('test', bootstrap_servers=['localhost:19092'], consumer_timeout_ms=2000, auto_offset_reset='earliest')
event = next(consumer)
#ConsumerRecord(topic='test', partition=0, offset=0, timestamp=1552733692669, timestamp_type=0, key=None, value=b'hello', headers=[], checksum=None, serialized_key_size=-1, serialized_value_size=5, serialized_header_size=-1)
for msg in consumer:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment