Created
November 29, 2021 08:30
-
-
Save Verina-Armanyous/30869240803665d827d5ee8fb8dc20be to your computer and use it in GitHub Desktop.
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 json import dumps | |
from kafka import KafkaProducer | |
# covert data to json and encode it to utf-8 | |
producer = KafkaProducer(bootstrap_servers=['localhost:9092'],value_serializer=lambda x:dumps(x).encode('utf-8')) | |
for e in range(5): | |
data = {'number': e} | |
producer.send('tutorial', value=data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment