项目作者: mbhamra

项目描述 :
PHP daemon for continue running kafka consumer code in background
高级语言: PHP
项目地址: git://github.com/mbhamra/KafkaManager.git
创建时间: 2019-09-22T09:58:31Z
项目社区:https://github.com/mbhamra/KafkaManager

开源协议:BSD 2-Clause "Simplified" License

下载


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

  1. 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

  1. # worker_dir/example_function.php
  2. function example_function($job, &$log) {
  3. // payload message consumed from topic
  4. $payload = $job->payload();
  5. // write your business logic here
  6. // Log is an array that is passed in by reference that can be
  7. // added to for logging data that is not part of the return data
  8. $log[] = "Success";
  9. // return your result to kafka manager to write in kafka manager log file
  10. return $result;
  11. }

Example by class

  1. # worker_dir/ExampleFunction.php
  2. class ExampleFunction {
  3. public function run($job, &$log) {
  4. // payload message consumed from topic
  5. $payload = $job->payload();
  6. // write your business logic here
  7. // Log is an array that is passed in by reference that can be
  8. // added to for logging data that is not part of the return data
  9. $log[] = "Success";
  10. // return your result to kafka manager to write in kafka manager log file
  11. return $result;
  12. }
  13. }

That’s all.
Enjoy your code. :)

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