Last active
May 20, 2020 01:52
-
-
Save bholagabbar/b780386b8527188002a46d8b9c8f8ada to your computer and use it in GitHub Desktop.
Write to kafka
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 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