euskadi31 / kafka-php
A PHP 5.3+ framework for Apache Kafka
v1.0.1
2016-02-23 14:18 UTC
Requires
- php: ^5.4
- ext-rdkafka: ^0.9.1
- ext-zookeeper: ^0.2.3
Requires (Dev)
- leaphub/phpcs-symfony2-standard: ~2.0.1
- phpunit/phpunit: ^4.7
- satooshi/php-coveralls: dev-master
This package is not auto-updated.
Last update: 2024-11-09 19:09:50 UTC
README
php-rdkafka improved to manage php-zookeeper.
Install
Add euskadi31/kafka-php
to your composer.json
:
% php composer.phar require euskadi31/kafka-php:~1.0
Usage
Producer
<?php $cm = new Euskadi31\Kafka\ClusterMetadata\Zookeeper([ '10.0.0.13' => 2181 ]); $producer = new Euskadi31\Kafka\Producer($cm); $topic = $producer->newTopic('test'); $topic->produce(RD_KAFKA_PARTITION_UA, 0, 'Message payload');
Consumer
<?php $cm = new Euskadi31\Kafka\ClusterMetadata\Zookeeper([ '10.0.0.13' => 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.