This project demonstrates how to set up and use Apache Kafka with Docker and Node.js. It includes examples of Kafka producer, consumer, and admin functionalities.
- Node.js: Download Node.js
- Docker: Download Docker
- VSCode: Download VSCode
-
Start Zookeeper Container
docker run -p PORTNO:PORTNO zookeeper
-
Start Kafka Container
docker run -p 9092:9092 \ -e KAFKA_ZOOKEEPER_CONNECT=<PRIVATE_IP>:2181 \ -e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://<PRIVATE_IP>:9092 \ -e KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR=1 \ confluentinc/cp-kafka
-
Run the Kafka Admin Script
node admin.js
-
Run the Kafka Producer
node producer.js
-
Run the Kafka Consumer
node consumer.js
-
node admin.js
Admin connecting... Admin Connection Success... Creating Topic [rider-updates] Topic Created Success [rider-updates] Disconnecting Admin..
-
node producer.js
connecting Producer producer connected producer disconnected
-
node consumer.js group1
group1: [rider-updates]: PART:0: {"name":"tony","location":"south"} group1: [rider-updates]: PART:1: {"name":"tony","location":"north"}