Giter VIP home page Giter VIP logo

kafkamanager's Introduction

Kafka Manager for PHP

Continue keep running consumers in background in php.

PHP daemon for kafka consumers

What is Kafka Manager and use ?

We need to keep running consumers for long time. Continue keep running any php file is very big task. We need to create many files with same code for every topic consumer. To reduce same code redundancy we create a manager which manage topic consumers with same code base. So you can focus on your business logic.

By using of this kafka manager, all you need to do is write the code that actually does the work and not all the repetitive worker setup. Just need to create files in specific directory. All files located in specified directory called as worker to consume messages from specific topic.

Pre Requisites

Installation Steps

Run following command with root user

sh install/install.sh

How it works ?

First of all, we need to create worker file(s) in specific directory. For this example, lets say we create a directory called worker_dir to hold all our worker code.

We can do this by two ways:

  • by function
  • by class

Example by function

# worker_dir/example_function.php

    function example_function($job, &$log) {
    
        // payload message consumed from topic
        $payload = $job->payload();
        
        // write your business logic here
    
        // Log is an array that is passed in by reference that can be
        // added to for logging data that is not part of the return data
        $log[] = "Success";
    
        // return your result to kafka manager to write in kafka manager log file
        return $result;

    }

Example by class

# worker_dir/ExampleFunction.php

    class ExampleFunction {
    
        public function run($job, &$log) {
        
            // payload message consumed from topic
            $payload = $job->payload();
            
            // write your business logic here
        
            // Log is an array that is passed in by reference that can be
            // added to for logging data that is not part of the return data
            $log[] = "Success";
        
            // return your result to kafka manager to write in kafka manager log file
            return $result;
    
        }
    }

That's all. Enjoy your code. :)

Thanks for using kafka manager and help us to make this perfect.

kafkamanager's People

Contributors

mbhamra avatar

Stargazers

 avatar

Watchers

 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.