This guide walkthrough setting up Apache Kafka with Zookeeper using Docker containers.
docker run -p 2181:2181 zookeeper
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
Replace <PRIVATE_IP> with your machine's private IP address. This command starts a Kafka container and connects it to the Zookeeper container.
npm install
node producer.js
This command starts the Kafka producer to send messages to the Kafka topic.
node consumer.js <GROUP_ID>
Replace <GROUP_ID> with the desired Kafka consumer group ID. This command starts the Kafka consumer to receive messages from the Kafka topic.