https://github.com/euskadi31/kafka-php
A PHP 5.3+ framework for Apache Kafka
https://github.com/euskadi31/kafka-php
kafka kafka-php
Last synced: 3 months ago
JSON representation
A PHP 5.3+ framework for Apache Kafka
- Host: GitHub
- URL: https://github.com/euskadi31/kafka-php
- Owner: euskadi31
- License: mit
- Created: 2016-02-18T16:23:55.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2016-02-23T14:48:32.000Z (over 9 years ago)
- Last Synced: 2025-01-19T18:49:19.204Z (5 months ago)
- Topics: kafka, kafka-php
- Language: PHP
- Size: 16.6 KB
- Stars: 1
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Kafka PHP
[](https://travis-ci.org/euskadi31/kafka-php)
[](https://insight.sensiolabs.com/projects/fe9e9f06-6ae2-416b-bfba-8962143e0443)
[](https://coveralls.io/github/euskadi31/kafka-php)
[](https://travis-ci.org/euskadi31/kafka-php)
[](https://packagist.org/packages/euskadi31/kafka-php)[php-rdkafka](https://github.com/arnaud-lb/php-rdkafka) improved to manage [php-zookeeper](https://github.com/andreiz/php-zookeeper).
## Install
Add `euskadi31/kafka-php` to your `composer.json`:
% php composer.phar require euskadi31/kafka-php:~1.0
## Usage
### Producer
```php
2181
]);$producer = new Euskadi31\Kafka\Producer($cm);
$topic = $producer->newTopic('test');
$topic->produce(RD_KAFKA_PARTITION_UA, 0, 'Message payload');
```### Consumer
```php
2181
]);$conf = new RdKafka\Conf();
$consumer = new Euskadi31\Kafka\Consumer($cm, $conf);
$topic = $consumer->newTopic('test');
$topic->consumeStart(0, RD_KAFKA_OFFSET_BEGINNING);
while (true) {
// The first argument is the partition (again).
// The second argument is the timeout.
$msg = $topic->consume(0, 1000);if (empty($msg)) {
continue;
}if ($msg->err) {
echo $msg->errstr() . PHP_EOL;
break;
} else {
echo $msg->payload . PHP_EOL;
}
}
```## License
kafka-php is licensed under [the MIT license](LICENSE.md).