Code Monkey home page Code Monkey logo

kafka-pub-sub's Introduction

Gitpod

NPM VersionNPM Monthly Downloads

Last Commit Language Most Used Implementations Repository Size

Forks Stars Watches

Author GitHub

kafka-pub-sub ๐Ÿ‘‹

kafka-pub-sub is designed based on KafkaJS with the support of stream processing that enables applications to publish, consume and process high volumes of record streams in a fast and durable way.

๐Ÿ”– Table Of Contents


๐ŸŒฑ Prerequisites

  • NPM/Yarn LTS
  • NodeJs

Back To The Top


โฌ Installing

๐Ÿ’ป Desktop

If you use Linux, try run commands bellow as sudo

npm i kafka-pub-sub

or

yarn add kafka-pub-sub

Back To The Top


๐Ÿ‘จโ€๐Ÿ’ป Example

Project stucture

project-structure

Note: Create NodeJS environment in both service-1 and service-2 and create server using your favourite NodeJS framewwork.

service-1/server.js

const ProduceEvent = require('kafka-pub-sub/ProduceEvent');

app.post('/api', async (req, res) => {
    const fakeData = {
        Name: "Md. Muhtasim Fuad Fahim",
        Email: "[email protected]",
    };

    const headers = { 
        'correlation-id': `1-${Date.now()}`,
        'system-id': 'my-system-id'
    };
    const producedEvent = await ProduceEvent('TEST_TOPIC', 'TEST_EVENT', fakeData, headers)
    console.log(producedEvent)

    return res.status(200).send("Done!");
});

service-2/server.js

const ConsumeEvent = require('kafka-pub-sub/ConsumeEvent');

(async function consumedEvent() {
    const consumedData = await ConsumeEvent('TEST_TOPIC')
    console.log(consumedData);
})();

service-1/.env & service-2/.env

KAFKA_CLIENT_ID=test-client
KAFKA_BROKER_URL=localhost:9092
KAFKA_GROUP_ID=test-group

sample docker-compose.yml

version: '2.1'
services:
  zookeeper:
    hostname: zookeeper
    container_name: zookeeper
    image: confluentinc/cp-zookeeper:latest
    environment:
      ZOOKEEPER_CLIENT_PORT: 2181
      ZOOKEEPER_TICK_TIME: 2000
  kafka:
    hostname: kafka
    container_name: kafka
    image: confluentinc/cp-kafka:latest
    depends_on:
      - zookeeper
    ports:
      - 9092:9092
    environment:
      KAFKA_BROKER_URL_ID: 1
      KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
      KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://localhost:9092
      KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
      KAFKA_INTER_BROKER_LISTENER_NAME: PLAINTEXT
      KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
      KAFKA_AUTO_CREATE_TOPICS_ENABLE: 'true'
      KAFKAJS_NO_PARTITIONER_WARNING: 1
      KAFKA_NUM_PARTITIONS: '6'

Now run the both services in your machine and hit the API. ๐Ÿฅณ

Back To The Top


๐Ÿ‘Œ Test

  • Fork it ๐Ÿ˜Ž
  • Clone forked repository: git clone https://github.com/username/forked-name.git
  • Install the dependencies from root directory: npm install
  • Rename .env.example to .env
  • Now run: npm run test & see the results ๐Ÿ˜Ž

๐Ÿ’ก How To Contribute

  • Fork it ๐Ÿ˜Ž
  • Create a feature branch: git checkout -b my-feature
  • Add your changes: git add .
  • Commit your changes: git commit -m 'My new feature'
  • Push to the branch: git push origin my-feature
  • Submit a pull request

Contributions, issues and features requests are welcome!
๐Ÿ“ฎ Submit PRs to help solve issues or add features
๐Ÿ› Find and report issues
๐ŸŒŸ Star the project

Back To The Top


๐Ÿ“ˆ Project Activity

Alt

Back To The Top


๐Ÿ‘ค Author

๐Ÿค“ Md. Muhtasim Fuad Fahim [email protected]

Back To The Top


๐Ÿ” License

Copyright ยฉ 2023 Md. Muhtasim Fuad Fahim

This project is licensed by MIT License.

Back To The Top


kafka-pub-sub's People

Contributors

mdmuhtasimfuadfahim avatar

Stargazers

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

Watchers

 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.