- Setup VS Code or any IDE with the root directory of the project having package.json file
- Run
npm install
from root directory - Run
node kafka_producer.js
to start the server - Now server is up and running
- Run
docker-compose -f docker-compose-kafka.yml up -d
from root directory of the project - Login to kafka docker container from Docker Desktop or using
docker exec -it <container> /bin/sh
command - Run
cd /opt/bitnami/kafka/bin
- Create a topic via command:
kafka-topics.sh --create --zookeeper zookeeper:2181 --replication-factor <replication factor> --partitions <partition count> --topic <topic name>
- Validate topic creation via command
kafka-topics.sh --list --zookeeper zookeeper:2181
- Kafka setup has completed successfully
- Update
$.kafka.host = localhost:9092
in config/default.json file - Run
node kafka_producer.js
to start the server - Now invoke relevant APIs using Chrome or PostMan to test the message publishing to Kafka
- To consume messages published to Kafka, modify kafka_test_consumer.js with relevant topic name and partition details
- Run
node kafka_test_consumer.js
Make sure that port 2181, 9092 is available on your machine as they are being used by Zookeeper and Kafka.