accolon/kara

Library management of Queue with Kafka

1.1.0 2020-07-08 01:31 UTC

This package is auto-updated.

Last update: 2024-12-08 10:51:30 UTC


README

Kara

Installing

composer require accolon/kara

Overview

Producers

// TestProducer.php
use Kara\Producer;
use Kara\Serialize;

class TestProducer extends Producer
{
    protected string $topic = "test";
    // Types: JSON, PHP, TEXT
    protected int $type = Serialize::JSON;
}

$producer = new TestProducer();
$producer->send([
    "message" => "Hello!"
]);

Consumers

// TestConsumer.php
use Kara\Consumer;
use Kara\Message;

class TestConsumer extends Consumer
{
    protected string $topic = "test";

    public function handle(Message $message)
    {
        echo "Topic: {$this->topic} -> " . $message->payload . "\n";
    }
}

Manager Consumer

// index.php
use Kara\ManagerConsumer;

$manager = new ManagerConsumer();

$manager->addConsumer(new TestConsumer());

$manager->run();

Run

Run consumers

php index.php