Skip to content

Instantly share code, notes, and snippets.

@sathiyarajanm
Created June 7, 2018 13:37
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 sathiyarajanm/bd8ef19fbc1568331316d46c2ef9fd81 to your computer and use it in GitHub Desktop.
Save sathiyarajanm/bd8ef19fbc1568331316d46c2ef9fd81 to your computer and use it in GitHub Desktop.
kafka-producer python from a file
from kafka import KafkaProducer
producer = KafkaProducer(bootstrap_servers=['localhost:9092'])
with open('/home/sathya/Documents/example.txt') as f:
lines = f.readlines()
for line in lines:
producer.send('topic-name',line)
print("done")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment