Skip to content

Instantly share code, notes, and snippets.

@nithyadurai87
Created November 23, 2020 17:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nithyadurai87/089138a14b0bca8024833fd3af03e54d to your computer and use it in GitHub Desktop.
Save nithyadurai87/089138a14b0bca8024833fd3af03e54d to your computer and use it in GitHub Desktop.
from pykafka import KafkaClient
import json
import time
client = KafkaClient(hosts='localhost:9092')
topic = client.topics['dataets']
producer = topic.get_sync_producer()
producer.produce(b'test message')
for e in range(1000):
data = {'number' : e}
print(data)
info_as_json = json.dumps(data)
producer.produce(info_as_json.encode('ascii'))
time.sleep(5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment