NodeJS ecommerce proof of concept example using Apache Kafka.
- A new order is created.
- The fraud detector do a verification to prevent payment frauds, it take some time to complete.
- An email is sent to buyer informing if the order was accepted or rejected by fraud detector.
- All messages are recived by log service.
NOTE: none of services above do a real job, is just a couple console.log's
.
In this project, are two topics ECOMMERCE_NEW_ORDER and ECOMMERCE_SEND_EMAIL. To add more topics add a new value to KAFKA_CREATE_TOPICS
in docker-compose.yml
separed by comma, the topic follow the NAME:PARTITIONS:REPLICAS:CLEANUP_POLICY
pattern.
The messages are serialized in JSON format.
More configurations are available here.
The communication between NodeJS and Kafka is provided by kafkaJS.
To run Kafka and Zookeeper run:
export HOST_IP=$(ifconfig | grep -E "([0-9]{1,3}\.){3}[0-9]{1,3}" | grep -v 127.0.0.1 | awk '{ print $2 }' | cut -f2 -d: | head -n1)
docker-compose up
Then, execute one service in each terminal
npm run log
npm run email
npm run fraud
To make an Order run:
npm run order
To change the fraud detection processing time create a .env
file at project root folder, and add a FRAUD DETECTION TIME
key in milliseconds, the default value is 2000ms (2 seconds).