Last active
September 11, 2017 09:32
-
-
Save rajkrrsingh/6a8bd45c1dbfb2a91376a163f2431eb1 to your computer and use it in GitHub Desktop.
sample kafka producer using python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
yum install -y python-pip | |
pip install kafka-python | |
//kafka producer sample code | |
vim kafka_producer.py | |
from kafka import KafkaProducer | |
from kafka.errors import KafkaError | |
producer = KafkaProducer(bootstrap_servers=['rkk1.hdp.local:6667']) | |
topic = "kafkatopic" | |
producer.send(topic, b'test message') | |
//run it | |
python kafka_producer.py | |
//test it | |
[root@rkk1 ~]# /usr/hdp/current/kafka-broker/bin/kafka-console-consumer.sh --zookeeper `hostname`:2181 --topic kafkatopic | |
{metadata.broker.list=rkk1.hdp.local:6667,rkk2.hdp.local:6667,rkk3.hdp.local:6667, request.timeout.ms=30000, client.id=console-consumer-41051, security.protocol=PLAINTEXT} | |
test message |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment