Git Product home page Git Product logo

kafka-experiment's Introduction

Kafka demo architecture

Overview

This is a straightforward demonstration of an Apache Kafka with NodeJS, featuring a dead letter queue functionality. Each message in the Kafka queue contains subscription data for an email campaign. The contact submission consumer's main task is to attempt the submission of the subscription data to a campaign API. In the event of a failure during this process, the message will be forwarded to the dead letter queue. Here, it will be accompanied by a reason for the failure and a timestamp, providing valuable information about the unsuccessful attempt.

Pre-requisites

  • Docker or you can setup kafka on your own
  • Nodejs >= 18.12.0.

Step 1: Bootstrap kafka

The provided docker compose file offers a easy quick setup for Kafka.

docker-compose up -d

Step 2: Create topics

To utilize the following commands, please download Kafka from official website to your local machine and navigate to the bin directory.

./kafka-topics.sh --create --bootstrap-server 127.0.0.1:9094 --replication-factor 1 --partitions 4 --topic contact-submission-queue
./kafka-topics.sh --create --bootstrap-server 127.0.0.1:9094 --replication-factor 1 --partitions 2 --topic dead-letter-queue

Created topics can be easily listed by running following command.

./kafka-topics.sh --list --bootstrap-server 127.0.0.1:9094

Output should be something like:

contact-submission-queue
dead-letter-queue

Step 3: Install packages from npm

$ npm i

Step 4: Setup environment variables

Copy .env.example to .env. Create a dummy campaign list at klaviyo and replace .env configuration with your credentials.

Step 5: Start consumers

The contact submission service is designed to retrieve messages from the contact-submission-queue and attempt to submit contact data to a third-party API. Contact submission service will join into a Kafka consumer group, you can deploy multiple instances of this service in various locations, enabling parallel processing of messages.

node src/contactSubmission.js

In the event of a failed contact submission due to an API error, the data will be moved to a dead letter, allowing for later analysis and investigation.

node src/deadLetter.js

Step 6: Send data to producer

node src/sendTestData.js
send to >>> contact-submission-queue - 1
...
send to >>> contact-submission-queue - 3

Useful commands

Describe a topic:

bin/kafka-topics.sh --describe --bootstrap-server 127.0.0.1:9094 --topic provider

Increase topic partitions:

bin/kafka-topics.sh --bootstrap-server 127.0.0.1:9094 --alter --topic provider --partitions 4

Author

Joynal Abedin - Joynal

License

This project is licensed under the MIT License - see the license.md file for details

kafka-experiment's People

Contributors

dependabot[bot] avatar joynal avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

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.