from kafka import KafkaProducer
from json import dumps
import time
producer = KafkaProducer(bootstrap_servers=['localhost:9092'],
value_serializer=lambda x: dumps(x).encode('utf-8'))
data = ['Hello from python', 'Theja from python']
producer.send('quickstart-events', data)
<kafka.producer.future.FutureRecordMetadata at 0x7f6a9365f9d0>
from kafka import KafkaConsumer
from json import loads
consumer = KafkaConsumer('quickstart-events',
bootstrap_servers=['localhost:9092'],
value_deserializer=lambda x: loads(x.decode('utf-8')))
for x in consumer:
print(x.value)
{'name': 'Theja'}