aerogram/adapter-kafka

There is no license information available for the latest version (0.3.0) of this package.

0.3.0 2017-06-20 10:33 UTC

This package is auto-updated.

Last update: 2020-11-17 02:19:52 UTC


README

Installation

You must install a bunch of things before installing this component:

  • A Kafka server, obviously (check Bitnami for a simple install).

  • librdkafka, the Kafka client library

  • rdkafka PHP extension. For example through PHPBrew:

    $ phpbrew ext install rdkafka
    

The recommended way to install aerogram/adapter-kafka is through Composer.

$ composer require aerogram/adapter-kafka

Usage

The following snippet instantiate a bus with a Kafka transport.

The Kafka stream is divided between 16 (0 to F) partitions based on the hash of the event hash.

<?php

use Aerogram\EventBus\EventBus\SimpleBus;
use Aerogram\EventBus\Kafka\KafkaTransport;
use Aerogram\EventBus\Kafka\Middleware\KafkaPartitioner;

$bus = new SimpleBus(
        new KafkaTransport,
        [
            new KafkaPartitioner(function($event, $options) {
                $hash = md5($event);

                return hexdec($hash{0});
            })
        ]
    );

// The following event will be published in partition 15
$bus->publish('event.test', '{"name": "test", "payload": "This is a test..."}');