Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/weiboad/kafka-php
kafka php client
https://github.com/weiboad/kafka-php
kafka kafka-consumer kafka-php php protocol
Last synced: about 1 month ago
JSON representation
kafka php client
- Host: GitHub
- URL: https://github.com/weiboad/kafka-php
- Owner: weiboad
- License: apache-2.0
- Archived: true
- Created: 2014-07-02T02:11:08.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2022-03-04T03:29:05.000Z (almost 3 years ago)
- Last Synced: 2024-09-07T07:08:01.395Z (3 months ago)
- Topics: kafka, kafka-consumer, kafka-php, php, protocol
- Language: PHP
- Homepage:
- Size: 926 KB
- Stars: 1,443
- Watchers: 82
- Forks: 450
- Open Issues: 119
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- favorite-link - kafka php 客户端。
- awesome-kafka - Php
- awesome-hacking-lists - weiboad/kafka-php - kafka php client (PHP)
README
Kafka-php
==========[中文文档](README_CH.md)
[![QQ Group](https://img.shields.io/badge/QQ%20Group-657517955-brightgreen.svg)]()
[![Build Status](https://travis-ci.org/weiboad/kafka-php.svg?branch=master)](https://travis-ci.org/weiboad/kafka-php)
[![Packagist](https://img.shields.io/packagist/dm/nmred/kafka-php.svg?style=plastic)]()
[![Packagist](https://img.shields.io/packagist/dd/nmred/kafka-php.svg?style=plastic)]()
[![Packagist](https://img.shields.io/packagist/dt/nmred/kafka-php.svg?style=plastic)]()
[![GitHub issues](https://img.shields.io/github/issues/weiboad/kafka-php.svg?style=plastic)](https://github.com/weiboad/kafka-php/issues)
[![GitHub forks](https://img.shields.io/github/forks/weiboad/kafka-php.svg?style=plastic)](https://github.com/weiboad/kafka-php/network)
[![GitHub stars](https://img.shields.io/github/stars/weiboad/kafka-php.svg?style=plastic)](https://github.com/weiboad/kafka-php/stargazers)
[![GitHub license](https://img.shields.io/badge/license-Apache%202-blue.svg?style=plastic)](https://raw.githubusercontent.com/weiboad/kafka-php/master/LICENSE)Kafka-php is a pure PHP kafka client that currently supports greater than 0.8.x version of Kafka, this project v0.2.x and v0.1.x are incompatible if using the original v0.1.x You can refer to the document
[Kafka PHP v0.1.x Document](https://github.com/weiboad/kafka-php/blob/v0.1.6/README.md), but it is recommended to switch to v0.2.x . v0.2.x use PHP asynchronous implementation and kafka broker interaction, more stable than v0.1.x efficient, because the use of PHP language so do not compile any expansion can be used to reduce the access and maintenance costs## Requirements
* Minimum PHP version: 7.1
* Kafka version greater than 0.8
* The consumer module needs kafka broker version greater than 0.9.0## Installation
Add the lib directory to the PHP include_path and use an autoloader like the one in the examples directory (the code follows the PEAR/Zend one-class-per-file convention).
## Composer Install
Simply add a dependency `nmred/kafka-php` to your project if you use Composer to manage the dependencies of your project.
`$ composer require nmred/kafka-php`Here is a minimal example of a composer.json file :
```
{
"require": {
"nmred/kafka-php": "0.2.*"
}
}
```## Configuration
Configuration properties are documented in [Configuration](docs/Configure.md)
## Producer
### Asynchronous mode
```php
pushHandler(new StdoutHandler());$config = \Kafka\ProducerConfig::getInstance();
$config->setMetadataRefreshIntervalMs(10000);
$config->setMetadataBrokerList('10.13.4.159:9192');
$config->setBrokerVersion('1.0.0');
$config->setRequiredAck(1);
$config->setIsAsyn(false);
$config->setProduceInterval(500);
$producer = new \Kafka\Producer(
function() {
return [
[
'topic' => 'test',
'value' => 'test....message.',
'key' => 'testkey',
],
];
}
);
$producer->setLogger($logger);
$producer->success(function($result) {
var_dump($result);
});
$producer->error(function($errorCode) {
var_dump($errorCode);
});
$producer->send(true);
```### Synchronous mode
```php
pushHandler(new StdoutHandler());$config = \Kafka\ProducerConfig::getInstance();
$config->setMetadataRefreshIntervalMs(10000);
$config->setMetadataBrokerList('127.0.0.1:9192');
$config->setBrokerVersion('1.0.0');
$config->setRequiredAck(1);
$config->setIsAsyn(false);
$config->setProduceInterval(500);
$producer = new \Kafka\Producer();
$producer->setLogger($logger);for($i = 0; $i < 100; $i++) {
$producer->send([
[
'topic' => 'test1',
'value' => 'test1....message.',
'key' => '',
],
]);
}
```## Consumer
```php
pushHandler(new StdoutHandler());$config = \Kafka\ConsumerConfig::getInstance();
$config->setMetadataRefreshIntervalMs(10000);
$config->setMetadataBrokerList('10.13.4.159:9192');
$config->setGroupId('test');
$config->setBrokerVersion('1.0.0');
$config->setTopics(['test']);
//$config->setOffsetReset('earliest');
$consumer = new \Kafka\Consumer();
$consumer->setLogger($logger);
$consumer->start(function($topic, $part, $message) {
var_dump($message);
});
```## Low-Level API
Refer [Example](https://github.com/weiboad/kafka-php/tree/master/example)
## QQ Group
Group 1: 531522091
Group 2: 657517955
![QQ Group](docs/qq_group.png)