2017 © Pedro Peláez
 

library php-rdkafka-bundle

Integrates php-rdkafka with Symfony2|3

image

mshauneu/php-rdkafka-bundle

Integrates php-rdkafka with Symfony2|3

  • Saturday, April 8, 2017
  • by mshauneu
  • Repository
  • 2 Watchers
  • 11 Stars
  • 5,662 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 7 Forks
  • 3 Open issues
  • 7 Versions
  • 29 % Grown

The README.md

KafkaBundle

About

This Symfony bundle provides connectivity to the Kafka publish-subscribe messaging system based on rdkafka binding to librdkafka, (*1)

Installation

Add the dependency in your composer.json, (*2)

{
    "require": {
        "mshauneu/php-rdkafka-bundle"
    }
}

Enable the bundle in your application kernel, (*3)

// app/AppKernel.php
public function registerBundles() {
    $bundles = array(
        // ...
        new Mshauneu\RdKafkaBundle\MshauneuRdKafkaBundle(),
    );
}

Configuration

Simple configuration could look like:, (*4)

mshauneu_rd_kafka:
  producers: 
    test_producer: 
      brokers: 127.0.0.1:9092
      topic: test_topic   
  consumers:
    test_consumer:
      brokers: 127.0.0.1:9092
      topic: test_topic   
      properties: 
        group_id: "test_group_id"
      topic_properties: 
        offset_store_method: broker           
        auto_offset_reset: smallest
        auto_commit_interval_ms: 100

Configuration properties are documented: - for producer or consumer in CommunicatorConfiguration.php - for topic to produce in TopicProducerConfiguration.php - for topic to consume in TopicConsumerConfiguration.php, (*5)

Usage

Publishing messages to a Kafka topic

From a Symfony controller:, (*6)

$payload = 'test_message';
$topicProducer = $container->get('mshauneu_rd_kafka')->getProducer("test_producer");
$topicProducer->produceStart();
$topicProducer->produce("message");
$topicProducer->produceStop();

By CLI:, (*7)

./app/console kafka:producer --producer test_producer test_message 

Consume messages out of a Kafka topic:

Implement ConsumerInterface, (*8)

class MessageHandler implements ConsumerInterface {
    public function consume($topic, $partition, $offset, $key, $payload) {
        echo "Received payload: " . $payload . PHP_EOL;
    }
}

Register it:, (*9)

test_message_handler:
    class: MessageHandler

From a Symfony controller:, (*10)

$topicConsumer = $container->get('mshauneu_rd_kafka')->getConsumer("test_producer");
$topicConsumer->consumeStart(TopicCommunicator::OFFSET_STORED);
$topicConsumer->consume($consumerImpl);
$topicConsumer->consumeStop();

By CLI:, (*11)

./app/console kafka:consumer --consumer test_consumer --handler test_message_handler 

License

This project is under the MIT License. See the LICENSE file for the full license text., (*12)

The Versions

08/04 2017

dev-master

9999999-dev

Integrates php-rdkafka with Symfony2|3

  Sources   Download

MIT

The Requires

 

The Development Requires

by Mikhail Shauneu

php symfony kafka

08/04 2017

1.0.5

1.0.5.0

Integrates php-rdkafka with Symfony2|3

  Sources   Download

MIT

The Requires

 

The Development Requires

by Mikhail Shauneu

php symfony kafka

28/01 2017

1.0.4

1.0.4.0

Integrates php-rdkafka with Symfony2|3

  Sources   Download

MIT

The Requires

 

The Development Requires

by Mikhail Shauneu

php symfony kafka

06/12 2016

1.0.3

1.0.3.0

Integrates php-rdkafka with Symfony2|3

  Sources   Download

MIT

The Requires

 

The Development Requires

by Mikhail Shauneu

php symfony kafka

30/11 2016

1.0.2

1.0.2.0

Integrates php-rdkafka with Symfony2|3

  Sources   Download

MIT

The Requires

 

The Development Requires

by Mikhail Shauneu

php symfony kafka

04/10 2016

1.0.1

1.0.1.0

Integrates php-rdkafka with Symfony2|3

  Sources   Download

MIT

The Requires

 

The Development Requires

by Mikhail Shauneu

php symfony kafka

25/07 2016