Giter Club home page Giter Club logo

kafka-nodejs-example's Introduction

Kafka NodeJS Example

Introduction

Demonstration

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):
docker-compose up
  1. Post a request to the sales endpoint specifying a total amount for the sale:
curl -X POST \
  http://localhost:8080/sales \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/x-www-form-urlencoded' \
  -d total=123.45
  1. Verify that Kafka received the data, and passed it to the consumer, which then added the sale to the database:
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.

[{"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"}]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.