An example how to use confluent_kafka python library to produce and consume json messages You can use an existing kafka broker or to run a docker kafka container The docker-compose.yaml is provided
- Replace localhost with hostname of your machine or leave it as is if you are planning to run docker container on your local machine
- Copy docker-compose.yml to your machine
docker-compose -f docker-compose.yml up -d
docker exec -it kafka /bin/sh
All Kafka shell scripts are located in /opt/kafka_/bin:
kafka-topics.sh --create --zookeeper zookeeper:2181 --replication-factor 1 --partitions 1 --topic my_first_topic
Verify that topic was created:
kafka-topics.sh --list --zookeeper zookeeper:2181
pip install requirements.txt
python producer.py localhost --topic my_first_topic
python consumer.py localhost --topic my_first_topic