Skip to content

Instantly share code, notes, and snippets.

@bholagabbar
Last active May 20, 2020 01:52
Show Gist options
  • Save bholagabbar/b780386b8527188002a46d8b9c8f8ada to your computer and use it in GitHub Desktop.
Save bholagabbar/b780386b8527188002a46d8b9c8f8ada to your computer and use it in GitHub Desktop.
Write to kafka
from time import sleep
from json import dumps
from kafka import KafkaProducer
# Create a producer to write data to kafka
producer = KafkaProducer(bootstrap_servers=['localhost:9092'],
value_serializer=lambda x: dumps(x).encode('utf-8'))
# Write data via the producer
for e in range(10):
data = {'number' : e}
producer.send(topic='numtest', value=data)
sleep(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment