PHPackages                             kim1ne/kafka - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. kim1ne/kafka

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

kim1ne/kafka
============

1.1.0(1y ago)210MITPHPPHP &gt;=8.1

Since Jan 12Pushed 1y ago1 watchersCompare

[ Source](https://github.com/kim1ne/kim1ne-kafka)[ Packagist](https://packagist.org/packages/kim1ne/kafka)[ RSS](/packages/kim1ne-kafka/feed)WikiDiscussions main Synced 2d ago

READMEChangelogDependencies (2)Versions (3)Used By (0)

Installation
============

[](#installation)

This package can be installed as a [Composer](https://getcomposer.org/) dependency.

```
composer require kim1ne/kafka
```

Usage
-----

[](#usage)

- [Kafka worker](#kafka-worker)
- [Launch several of workers](#launch-several-of-workers)
- [API](#api)

#### Kafka Worker

[](#kafka-worker)

This is wrap of the library [RdKafka](https://arnaud.le-blanc.net/php-rdkafka-doc/phpdoc/index.html). The library uses libraries of the [ReactPHP](https://reactphp.org/) for async. Stream doesn't lock.

```
use Kim1ne\InputMessage;
use Kim1ne\Kafka\KafkaConsumer;
use Kim1ne\Kafka\KafkaWorker;
use Kim1ne\Kafka\Message;
use RdKafka\Conf;

$conf = new Conf();
$conf->set('metadata.broker.list', 'kafka:9092');
$conf->set('group.id', 'my-group');
// $conf->set(...) other settings

$worker = new KafkaWorker($conf);

$worker->subscribe(['my-topic'])

$worker
    ->on(function (Message $message, KafkaConsumer $consumer) {
        $consumer->commitAsync($message);
    })
    ->critical(function (\Throwable $throwable) {
        InputMessage::red('Error: ' . $throwable->getMessage());
    });

InputMessage::green('Start Worker');

$worker->run();
```

### Launch several of workers

[](#launch-several-of-workers)

The functional starts [event loop](https://reactphp.org/event-loop/#usage) and locks stream.

```
use Kim1ne\InputMessage;
use Kim1ne\Kafka\KafkaConsumer;
use Kim1ne\Kafka\Message;
/**
 * @var \RdKafka\Conf $conf
 */
\Kim1ne\Kafka\ParallelWorkers::start(
    (new \Kim1ne\Kafka\KafkaWorker($conf))
        ->subscribe(['topic-1'])
        ->on(function (Message $message, KafkaConsumer $consumer) {
            InputMessage::red('Message in the first worker!')
        }),
    (new \Kim1ne\Kafka\KafkaWorker($conf))
        ->subscribe(['topic-2'])
        ->on(function (Message $message, KafkaConsumer $consumer) {
            InputMessage::red('Message in the second worker!')
        }),
    // ... $workerN
);
```

### API

[](#api)

This callback will be called on message from the kafka

```
use Kim1ne\Kafka\Message;
use Kim1ne\Kafka\KafkaConsumer;

$worker
    ->on(function(Message $message, KafkaConsumer $consumer) {
        // Message!
    });
```

This callback will be called if bad message

```
use Kim1ne\Kafka\Message;

$worker
    ->error(function (Message $message) {
        // the callback for bad message
        // $message->err !== RD_KAFKA_RESP_ERR_NO_ERROR
        // except messages with error code === RD_KAFKA_RESP_ERR__TIMED_OUT
    });
```

In this callback will be called, will be thrown out an exception

```
$worker
    ->critical(function (\Throwable $e) {
        // Error
    })
```

Stops the worker. If is parallel process, that destroys the worker and if he is last, stops the event-loop

```
$worker->stop();
```

Sets timeout for call method of the [RdKafka\\Consumer::consume($timeout\_ms)](https://arnaud.le-blanc.net/php-rdkafka-doc/phpdoc/rdkafka-kafkaconsumer.consume.html)

```
$worker->setTimeoutMs(1000); // default is 0
```

Returns object of the [RdKafka\\Consumer:::class](https://arnaud.le-blanc.net/php-rdkafka-doc/phpdoc/class.rdkafka-kafkaconsumer.html)

```
$consumer = $worker->getConsumer();
```

turns off the sleep mode. Will be too many errors, the worker will continue the work

```
$worker->noSleep();
```

Returns attempts of again processing

```
/**
 * @var \Kim1ne\Kafka\Message $message
 */
$message->getAttempts();
```

commits current message, creates duplicate the message, increments attempt on 1 and sends to the end the topic. the topic may be specified, otherwise will be selected the topic of the message

```
/**
 * @var \Kim1ne\Kafka\KafkaConsumer $consumer
 */

$consumer->retry(Message $message, ?string $overrideTopicName = null, int $timeWaiting = 10_000);
```

```
use Kim1ne\Kafka\Message;
use Kim1ne\Kafka\KafkaConsumer;

$worker
    ->on(function (Message $message, KafkaConsumer $consumer) {
        $attempts = $message->getAttempts();

        if ($attempts < 3) {
            $consumer->retry($message);
            return;
        }

        $consumer->commitAsync($message);
    });
```

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance40

Moderate activity, may be stable

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~31 days

Total

2

Last Release

505d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/111231185?v=4)[kim1ne](/maintainers/kim1ne)[@kim1ne](https://github.com/kim1ne)

---

Top Contributors

[![kim1ne](https://avatars.githubusercontent.com/u/111231185?v=4)](https://github.com/kim1ne "kim1ne (1 commits)")

### Embed Badge

![Health badge](/badges/kim1ne-kafka/health.svg)

```
[![Health](https://phpackages.com/badges/kim1ne-kafka/health.svg)](https://phpackages.com/packages/kim1ne-kafka)
```

###  Alternatives

[composer/composer

Composer helps you declare, manage and install dependencies of PHP projects. It ensures you have the right stack everywhere.

29.5k196.2M3.1k](/packages/composer-composer)[ccxt/ccxt

A cryptocurrency trading API with more than 100 exchanges in JavaScript / TypeScript / Python / C# / PHP / Go

43.2k341.0k1](/packages/ccxt-ccxt)[react/react

ReactPHP: Event-driven, non-blocking I/O with PHP.

9.1k3.7M65](/packages/react-react)[reactivex/rxphp

Reactive extensions for php.

1.7k3.3M55](/packages/reactivex-rxphp)[internal/dload

Downloads binaries.

102212.3k19](/packages/internal-dload)[team-reflex/discord-php

An unofficial API to interact with the voice and text service Discord.

1.1k420.9k26](/packages/team-reflex-discord-php)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
