PHPackages                             ensi/laravel-phprdkafka - 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. [HTTP &amp; Networking](/categories/http)
4. /
5. ensi/laravel-phprdkafka

ActiveLibrary[HTTP &amp; Networking](/categories/http)

ensi/laravel-phprdkafka
=======================

Bridge package between Laravel and php-rdkafka

0.4.6(3mo ago)599.6k↓27.4%22MITPHPPHP ^8.1CI passing

Since Apr 5Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/ensi-platform/laravel-php-rdkafka)[ Packagist](https://packagist.org/packages/ensi/laravel-phprdkafka)[ RSS](/packages/ensi-laravel-phprdkafka/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (9)Versions (22)Used By (2)

Bridge package between Laravel and php-rdkafka
==============================================

[](#bridge-package-between-laravel-and-php-rdkafka)

[![Latest Version on Packagist](https://camo.githubusercontent.com/52f97464a52bb3f71499820ed6f2774496ee428fe734d35bf89dd1293637be52/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f656e73692f6c61726176656c2d70687072646b61666b612e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ensi/laravel-phprdkafka)[![Tests](https://github.com/ensi-platform/laravel-php-rdkafka/actions/workflows/run-tests.yml/badge.svg?branch=master)](https://github.com/ensi-platform/laravel-php-rdkafka/actions/workflows/run-tests.yml)[![Total Downloads](https://camo.githubusercontent.com/427a2f2abcf40a476f88694bfb552717609a23b37a9d2735ef9f622c0d4f6664/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f656e73692f6c61726176656c2d70687072646b61666b612e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ensi/laravel-phprdkafka)

This packages allows you to describe Kafka producers and consumers in config/kafka.php and then reuse them everywhere.

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require ensi/laravel-phprdkafka
```

Publish the config file with:

```
php artisan vendor:publish --provider="Ensi\LaravelPhpRdKafka\LaravelPhpRdKafkaServiceProvider" --tag="kafka-config"
```

Now go to `config/kafka.php` and configure your producers and consumers there. You typically need one producer/consumer per Kafka Cluster. Configuration parameters can found in [Librdkafka Configuration reference](https://github.com/edenhill/librdkafka/blob/master/CONFIGURATION.md)

Version Compatibility
---------------------

[](#version-compatibility)

Laravel rdkakfaLaravelPHPext-rdkafka^0.1.0^7.x || ^8.x^7.3 || ^8.0^5.0^0.2.0^7.x || ^8.x^7.3 || ^8.0^5.0^0.2.1^7.x || ^8.x^7.3 || ^8.0^5.0 || ^6.0^0.2.2^8.x || ^9.x^7.3 || ^8.0^5.0 || ^6.0^0.3.0^8.x || ^9.x^7.3 || ^8.0^5.0 || ^6.0^0.3.3^8.x || ^9.x || ^10.x^7.3 || ^8.0^5.0 || ^6.0^0.3.4^8.x || ^9.x || ^11.x^7.3 || ^8.0^5.0 || ^6.0^0.4.0^9.x || ^10.x || ^11.x^8.1^5.0 || ^6.0^0.4.5^9.x || ^10.x || ^11.x || ^12.x^8.1^5.0 || ^6.0Basic Usage
-----------

[](#basic-usage)

Producer example:

```
$producer = \Kafka::producer('producer-name'); // returns a configured RdKafka\Producer singleton.
// or $producer = \Kafka::producer(); if you want to get the default producer.
// or $producer = $kafkaManager->producer(); where $kafkaManager is an instance of Ensi\LaravelPhpRdKafka\KafkaManager resolved from the service container.

// now you can implement any producer logic e.g:

$headers = [];
$topicName = 'test-topic';
$topic = $producer->newTopic($topicName);
for ($i = 0; $i < 10; $i++) {
   $payload = json_encode([
      'body' => "Message $i in topic [$topicName]",
      'headers' => $headers
   ]);
   $topic->produce(RD_KAFKA_PARTITION_UA, 0, $payload);
   $producer->poll(0);
}

for ($flushRetries = 0; $flushRetries < 10; $flushRetries++) {
   $result = $producer->flush(10000);
   if (RD_KAFKA_RESP_ERR_NO_ERROR === $result) {
      break;
   }
}
if (RD_KAFKA_RESP_ERR_NO_ERROR !== $result) {
   // Log and/or throw "Unable to flush Kafka producer, messages of topic [$topicName] might be lost.' exception.
}

// If you use php-fpm and producing is slow you can move its execution to the place after response has been sent.
// This can be achieved e.g. by wrapping the whole producing or at least flushing in it in a "terminating" callback.
// app()->terminating(function () { ... });
```

Consumer example:

```
public function handle(KafkaManager $kafkaManager)
{
   $consumer = $kafkaManager->consumer('consumer-name');
   $consumer->subscribe(['test-topic-1', 'test-topic-2']);

   while (true) {
      $message = $consumer->consume(120*1000);
      switch ($message->err) {
            case RD_KAFKA_RESP_ERR_NO_ERROR:
               $this->info($message->payload);
               $this->processMessage($message); // do something with the message
               // $consumer->commitAsync($message); // commit offsets asynchronously if you set 'enable.auto.commit' => false, in config/kafka.php
               break;
            case RD_KAFKA_RESP_ERR__PARTITION_EOF:
               echo "No more messages; will wait for more\n";
               break;
            case RD_KAFKA_RESP_ERR__TIMED_OUT:
               // this also happens when there is no new messages in the topic after the specified timeout: https://github.com/arnaud-lb/php-rdkafka/issues/343
               echo "Timed out\n";
               break;
            default:
               throw new Exception($message->errstr(), $message->err);
               break;
      }
   }
}
```

You can learn more about php-rdkafka producers and consumers [php-rdkafka examples](https://arnaud.le-blanc.net/php-rdkafka-doc/phpdoc/rdkafka.examples.html)

Direct access to `RdKafka\Conf` instances is available with the following getters:

```
$producerConf = $kafkaManager->producerConfig('producer-name');
$consumerConf = $kafkaManager->consumerConfig('consumer-name');
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.

### Testing

[](#testing)

1. composer install
2. composer test

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](.github/SECURITY.md) on how to report security vulnerabilities.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

52

—

FairBetter than 96% of packages

Maintenance78

Regular maintenance activity

Popularity37

Limited adoption so far

Community20

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

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 ~92 days

Recently: every ~82 days

Total

20

Last Release

116d ago

PHP version history (2 changes)0.1.0PHP ^7.3 || ^8.0

0.4.0PHP ^8.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/8089373?v=4)[Наталия](/maintainers/MsNatali)[@MsNatali](https://github.com/MsNatali)

![](https://avatars.githubusercontent.com/u/7352966?v=4)[Andrey](/maintainers/dimionx)[@DimionX](https://github.com/DimionX)

---

Top Contributors

[![C0rTeZ13](https://avatars.githubusercontent.com/u/120840631?v=4)](https://github.com/C0rTeZ13 "C0rTeZ13 (29 commits)")[![MsNatali](https://avatars.githubusercontent.com/u/8089373?v=4)](https://github.com/MsNatali "MsNatali (27 commits)")[![arrilot](https://avatars.githubusercontent.com/u/2826480?v=4)](https://github.com/arrilot "arrilot (3 commits)")[![MadridianFox](https://avatars.githubusercontent.com/u/3392587?v=4)](https://github.com/MadridianFox "MadridianFox (3 commits)")[![valerialukinykh](https://avatars.githubusercontent.com/u/123940772?v=4)](https://github.com/valerialukinykh "valerialukinykh (2 commits)")[![DimionX](https://avatars.githubusercontent.com/u/7352966?v=4)](https://github.com/DimionX "DimionX (2 commits)")[![eugene-holiday](https://avatars.githubusercontent.com/u/1556306?v=4)](https://github.com/eugene-holiday "eugene-holiday (1 commits)")

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/ensi-laravel-phprdkafka/health.svg)

```
[![Health](https://phpackages.com/badges/ensi-laravel-phprdkafka/health.svg)](https://phpackages.com/packages/ensi-laravel-phprdkafka)
```

###  Alternatives

[binaryk/laravel-restify

Laravel REST API helpers

651399.1k](/packages/binaryk-laravel-restify)[namu/wirechat

A Laravel Livewire messaging app for teams with private chats and group conversations.

54324.5k](/packages/namu-wirechat)[lomkit/laravel-rest-api

A package to build quick and robust rest api for the Laravel framework.

59152.2k](/packages/lomkit-laravel-rest-api)[wirechat/wirechat

A Laravel Livewire messaging app for teams with private chats and group conversations.

5434.7k](/packages/wirechat-wirechat)[api-platform/laravel

API Platform support for Laravel

59126.4k6](/packages/api-platform-laravel)[georgeboot/laravel-echo-api-gateway

Use Laravel Echo with API Gateway Websockets

10435.5k](/packages/georgeboot-laravel-echo-api-gateway)

PHPackages © 2026

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