Skip to content

Instantly share code, notes, and snippets.

@Verina-Armanyous
Created November 29, 2021 08:30
Show Gist options
  • Save Verina-Armanyous/30869240803665d827d5ee8fb8dc20be to your computer and use it in GitHub Desktop.
Save Verina-Armanyous/30869240803665d827d5ee8fb8dc20be to your computer and use it in GitHub Desktop.
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