2017 © Pedro Peláez
 

library php-pubsub-kafka

A Kafka adapter for the php-pubsub package

image

superbalist/php-pubsub-kafka

A Kafka adapter for the php-pubsub package

  • Thursday, May 18, 2017
  • by matthewgoslett
  • Repository
  • 24 Watchers
  • 13 Stars
  • 16,646 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 4 Forks
  • 2 Open issues
  • 6 Versions
  • 7 % Grown

The README.md

php-pubsub-kafka

A Kafka adapter for the php-pubsub package., (*1)

Author Build Status StyleCI Software License Packagist Version Total Downloads, (*2)

Installation

  1. Install librdkafka c library, (*3)

    $ cd /tmp
    $ mkdir librdkafka
    $ cd librdkafka
    $ git clone https://github.com/edenhill/librdkafka.git .
    $ ./configure
    $ make
    $ make install
    
  2. Install the php-rdkafka PECL extension, (*4)

    $ pecl install rdkafka
    
  3. Add the following to your php.ini file to enable the php-rdkafka extension extension=rdkafka.so, (*5)

  4. composer require superbalist/php-pubsub-kafka, (*6)

Usage

// create consumer
$topicConf = new \RdKafka\TopicConf();
$topicConf->set('auto.offset.reset', 'largest');

$conf = new \RdKafka\Conf();
$conf->set('group.id', 'php-pubsub');
$conf->set('metadata.broker.list', '127.0.0.1');
$conf->set('enable.auto.commit', 'false');
$conf->set('offset.store.method', 'broker');
$conf->set('socket.blocking.max.ms', 50);
$conf->setDefaultTopicConf($topicConf);

$consumer = new \RdKafka\KafkaConsumer($conf);

// create producer
$conf = new \RdKafka\Conf();
$conf->set('socket.blocking.max.ms', 50);
$conf->set('queue.buffering.max.ms', 20);

$producer = new \RdKafka\Producer($conf);
$producer->addBrokers('127.0.0.1');

$adapter = new \Superbalist\PubSub\Kafka\KafkaPubSubAdapter($producer, $consumer);

// consume messages
// note: this is a blocking call
$adapter->subscribe('my_channel', function ($message) {
    var_dump($message);
});

// publish messages
$adapter->publish('my_channel', 'HELLO WORLD');
$adapter->publish('my_channel', ['hello' => 'world']);
$adapter->publish('my_channel', 1);
$adapter->publish('my_channel', false);

// publish multiple messages
$messages = [
    ['hello' => 'world'],
    'lorem ipsum',
];
$adapter->publishBatch('my_channel', $messages);

Examples

The library comes with examples for the adapter and a Dockerfile for running the example scripts., (*7)

Run make up., (*8)

You will start at a bash prompt in the /opt/php-pubsub directory., (*9)

If you need another shell to publish a message to a blocking consumer, you can run make shell, (*10)

To run the examples:, (*11)

$ php examples/KafkaConsumerExample.php
$ php examples/KafkaPublishExample.php (in a separate shell)

The Versions

18/05 2017

dev-master

9999999-dev

A Kafka adapter for the php-pubsub package

  Sources   Download

MIT

The Requires

 

The Development Requires

by Superbalist.com a division of Takealot Online (Pty) Ltd

18/05 2017

2.0.0

2.0.0.0

A Kafka adapter for the php-pubsub package

  Sources   Download

MIT

The Requires

 

The Development Requires

by Superbalist.com a division of Takealot Online (Pty) Ltd

06/02 2017

dev-analysis-8KLDjD

dev-analysis-8KLDjD

A Kafka adapter for the php-pubsub package

  Sources   Download

MIT

The Requires

 

The Development Requires

by Superbalist.com a division of Takealot Online (Pty) Ltd

08/09 2016

1.0.2

1.0.2.0

A Kafka adapter for the php-pubsub package

  Sources   Download

MIT

The Requires

 

The Development Requires

by Superbalist.com a division of Takealot Online (Pty) Ltd

07/09 2016

1.0.1

1.0.1.0

A Kafka adapter for the php-pubsub package

  Sources   Download

MIT

The Requires

 

The Development Requires

by Superbalist.com a division of Takealot Online (Pty) Ltd

03/09 2016

1.0.0

1.0.0.0

A Kafka adapter for the php-pubsub package

  Sources   Download

MIT

The Requires

 

The Development Requires

by Superbalist.com a division of Takealot Online (Pty) Ltd