Sample project to demonstrate NodeJS and Apache Kafka (Windows)
- Prerequisites
- Configuration
- Running Application
- Project Structure
Tool | Version |
---|---|
Node JS | 8.11.x |
kafka | kafka_2.12-2.3.0 |
zookeeper | zookeeper-3.5.5 |
-
Update kafka server.properties
/kafka_2.12-2.3.0/config/server.properties
-
Copy zoo_sample.cfg to zoo.cfg and update dataDir (The directory where the snapshot is stored) value
/zookeeper-3.5.5/conf/zoo.cfg
-
Start ZooKeeper
Open a command prompt and type zkserver
-
Start kafka service - Under kafka extracted directory
kafka_2.12-2.3.0 >.\bin\windows\kafka-server-start.bat .\config\server.properties
-
Create two topics (As per configuration /config/config.development.js)
'TEST_TOPIC' and 'NODE_KAFKA'
kafka-topics.bat --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic TEST_TOPIC
kafka-topics.bat --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic NODE_KAFKA
-
Under roor directory - Spin up kafka consumers
node src/index.js
-
To generate message
node kafka-producers/node_kafka.producer.js
-
Message received at kafka-consumer - NODE_KAFKA
Log folder : node-apache-kafka/logs/node_topic_out.log
Output : Message received at NODE_KAFKA. Message [ NODE_KAFKA ]
.
├── node-apache-kafka
| ├── /config # Configuration files
| ├── /kafka-consumers # Kafka Consumers scripts
| ├── /kafka-producers # Kafka Producers scripts
| ├── /logs # Log files
│ | ├── *_out.log # Stdout logs
│ | ├── *.log # Log
│ | └── *_err.log # Stderr logs
| ├── /src # Source scripts
│ | └── index.js # Entry point file - _Spin up consumers_
| ├── /node_modules # Contains Node packages as specified as dependencies in package.json
│ | ├── : # -|-
│ | ├── : # -|-
│ | └── : # -|-
│ ├── .gitignore # git configuration to ignore some files and folder
│ ├── package.json # Standard npm package specification
│ ├── LICENSE # LICENSE information
└───└── README.md # **node-apache-kafka** documentation