Apache Kafka is a distributed publish-subscribe messaging system developed by LinkedIn and written in Scala and Java.
- Install Java SDK (required Java 8+).
- Download and Install Apache Kafka Binaries from the following link.
- Extract the folder and move it to local disk C Drive.
- Create 'zookeeper' and 'kafka-logs' folders for storing zookeeper data and kafka logs.
- Modify
dataDir=/tmp/zookeeper
in config.properties todataDir=C:/kafka/zookeeper
. - Modify
log.dirs=/tmp/kafka-logs
in config/server.properties tolog.dirs=C:/kafka/kafka-logs
.
.\bin\windows\zookeeper-server-start.bat .\config\zookeeper-properties
.\bin\windows\kafka-server-start.bat .\config\server.properties
.\bin\windows\kafka-topics.bat --create --bootstrap-server localhost:9092 --topic cities
.\bin\windows\kafka-console-producer.bat --broker-list localhost:9092 --topic cities
.\bin\windows\kafka-console-consumer.bat --bootstrap-server localhost:9092 --topic cities --from-beginning
In order to use Kafka with Python you need to first install kafka-python, to do so use following command:
pip install kafka-python
Note: Before sending any messages to Kafka servers, make sure to first start your Kafka cluster!
To send a string data to the Kafka Server using Python run the following script:
python producer.py
To send a continuous dummy real-time IOT sensors data to the Kafka server run the following script:
python producer-sensor.py
To send CSV data to the kafka server line by line run the following script:
python producer-csv.py
To send a MySQL Database to the Kafka Server run the following script:
python producer-mysql.py
To consume messages from a Kafka server in python for a specific topic run the following script:
python consumer.py