Write data to Kafka using Python

chnhbhndchngn 2022-02-13 08:18:14 阅读数:807

write data kafka using python

The first step is to install pykafka

pip install pykafka

PyKafka — pykafka 2.8.1-dev.2 documentation

The second step is to write the data code of the corresponding subject , Here are just demo

from pykafka import KafkaClient
client = KafkaClient(hosts=",,")
topic = client.topics['tea']
with topic.get_sync_producer() as producer:
for i in range(10000):
producer.produce(('test message ' + str(i)).encode())

copyright:author[chnhbhndchngn],Please bring the original link to reprint, thank you. https://en.javamana.com/2022/02/202202130818124110.html