Skip to content

Instantly share code, notes, and snippets.

@cloudlakecho
Created February 25, 2023 05:29
Show Gist options
  • Save cloudlakecho/53d6fb38b3673c756ffbb0caf1d1e0af to your computer and use it in GitHub Desktop.
Save cloudlakecho/53d6fb38b3673c756ffbb0caf1d1e0af to your computer and use it in GitHub Desktop.
Producer using Kafka and ZooKeeper
# Steven Van Dorpe, Aug 13, 2018
#
# Reference:
# https://towardsdatascience.com/kafka-python-explained-in-10-lines-of-code-800e3e07dad1
from time import sleep
from json import dumps
from kafka import KafkaProducer
producer = KafkaProducer(bootstrap_servers=['localhost:9092'],
value_serializer=lambda x:
dumps(x).encode('utf-8'))
for e in range(1000):
data = {'number' : e}
producer.send('numtest', value=data)
sleep(5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment