Giter Club home page Giter Club logo

kafka-consumer's Introduction

kafka-consumer

An AWS KAfka twitter stream consumming appliction runnng on a cron schedular

Dependencies

  • kafka-node
  • redis
  • node-cron

Note:

This project is just one of the first layer implementation on twitter to aws kafka-server ETL pipelining and is it still expected to scale up.

_init function

This is a initialization function that takes in the kafka-host config object and parse into the kakfa-interface createClient method for further implementation .This init method is run by the cron sheduler for every 1-5 min which is then written to a log folder

function _init(host){
        var kafka_consumer = consumer(host);
        kafka_consumer.recievePayload(payload);

};
eg :
  _init({
                kafkaHost:
                        "52.19.199.252:9092,52.19.199.252:9093,52.19.199.252:9094"
        });

Note : the payload is the consumed data from AWS-Kafka

const payload = [
        {
                topic: "caleb_twitter_stream_topic"
        }
];
class KafkaConsumerInterface {
        constructor(host) {
                this.host = host;
        }
        // creates a kafka client with specified host
        createClient(host) {
                return new Kafka.KafkaClient(host, {
                        sessionTimeout: 20,
                        spinDelay: 10,
                        retries: 2
                });
        }
        //  return an instance of a kafka_consumer
        createConsumer(payload, option = {}) {
                var client = this.createClient(this.host);
                return new KafkaConsumer(client, payload, option);
        }

        recievePayload(payload, option = {}) {
                console.log(payload);
                          // create consumer with the payload
                return this.createConsumer(payload, (option = {})).on(
                        "message",
                        msg => {
                                var today = new Date();
                                var time = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();
                                var newMsg = JSON.stringify(msg);
                                fs.writeFileSync(
                                        `logs/${msg.topic}_${time}.json`,newMsg,(err)=>{
                                                if(err){
                                                        throw new Error("Writing error");
                                                }
                                        }
                                )
                        }
                );
        }
        

kafka-consumer's People

Contributors

caleberi avatar dependabot[bot] avatar

Watchers

 avatar  avatar  avatar

Forkers

drlsv91

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.