Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/chatthana/kafka-nodejs-boilerplate
Boilerplate of Node.js application with Kafka integration
https://github.com/chatthana/kafka-nodejs-boilerplate
Last synced: 22 days ago
JSON representation
Boilerplate of Node.js application with Kafka integration
- Host: GitHub
- URL: https://github.com/chatthana/kafka-nodejs-boilerplate
- Owner: chatthana
- License: mit
- Created: 2020-02-21T09:47:00.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2022-12-09T01:13:26.000Z (about 2 years ago)
- Last Synced: 2023-03-11T21:48:47.511Z (almost 2 years ago)
- Language: JavaScript
- Size: 1.25 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Kafka NodeJS Example
## Introduction
![Demonstration](https://raw.githubusercontent.com/anthonyhastings/kafka-nodejs-example/master/images/kafka-nodejs-example.gif)This repository showcases an example of using Kafka with NodeJS. In this example, we use Kafka as a messaging system for inserting hypothetical sales into a database. Instead of our sales endpoint hitting the database directly, it pushes sale data to Kafka, thus acting as a 'producer'. We spin up a 'consumer' that will take data from Kafka and push it into the database.
## Instructions
This demonstration assumes you already have `docker` and `docker-compose` installed. The steps are as follows:1) Using `docker-compose`, spin up all containers (Zookeeper, Kafka, Database, Producer and Consumer):
```shell
docker-compose up
```2) Post a request to the sales endpoint specifying a total amount for the sale:
```shell
curl -X POST \
http://localhost:8080/sales \
-H 'cache-control: no-cache' \
-H 'content-type: application/x-www-form-urlencoded' \
-d total=123.45
```3) Verify that Kafka received the data, and passed it to the consumer, which then added the sale to the database:
```shell
curl -X GET http://localhost:8080/sales
```Upon first run, this last command should return JSON containing an initial seed record for the database, along with the sale posted in the previous step.
```json
[{"id":1,"uuid":"675867b9-e318-44be-8560-774e59601340","total":"10.66","sale_date":"2018-07-15T22:25:14.930Z","created_at":"2018-07-15T22:25:14.930Z"},{"id":2,"uuid":"7da94758-ea1e-4eed-af85-877bf421e2dd","total":"123.45","sale_date":"2018-07-15T22:25:31.364Z","created_at":"2018-07-15T22:25:31.403Z"}]
```