Hello World In Kafka Using Python and Docker
$ sudo docker-compose up -d
Creating a producer and consumer can be a perfect Hello, World! example to learn Kafka but there are multiple ways through which we can achieve it. Some of them are listed below:
- Command line client provided as default by Kafka
- kafka-python
- PyKafka
- confluent-kafka
we will be making use of confluent-kafka to achieve a simple producer and consumer setup in Kafka using python.
$ pip3 install -r requirements.txt
Open a new terminal and run the Kafka consumer. Consumer will be in listening stage continuously.
$ python3 kafka_consumer.py
Open a new terminal and run the Kafka Producer, which produce "Hello World!".
$ python3 kafka_producer.py
You can now revisit the consumer shell to check if it has received the records sent from the producer through our Kafka setup.