PHPackages                             ensi/laravel-phprdkafka-consumer - 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. [Queues &amp; Workers](/categories/queues)
4. /
5. ensi/laravel-phprdkafka-consumer

ActiveLibrary[Queues &amp; Workers](/categories/queues)

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

Opiniated High Level consumer for laravel-phprdkafka

2.0.8(4mo ago)664.1k↓29%3MITPHPPHP ^8.1CI passing

Since Sep 30Pushed 4mo ago1 watchersCompare

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

READMEChangelog (10)Dependencies (10)Versions (25)Used By (0)

Laravel PHP Rdkafka Consumer
============================

[](#laravel-php-rdkafka-consumer)

[![Latest Version on Packagist](https://camo.githubusercontent.com/2eeb0d2b6bcc6e8f41b292ad6573dd0596275ea30aa12833bbd937e7ae5829c6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f656e73692f6c61726176656c2d70687072646b61666b612d636f6e73756d65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ensi/laravel-phprdkafka-consumer)[![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/7433b6395f51f1660753f562aa3f8d0a03e0d10ecb1a345e89ce68f43796f9b1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f656e73692f6c61726176656c2d70687072646b61666b612d636f6e73756d65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ensi/laravel-phprdkafka-consumer)

Opiniated High Level consumer for [ensi/laravel-phprdkafka](https://github.com/ensi-platform/laravel-php-rdkafka)

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

[](#installation)

Firstly, you have to install and configure [ensi/laravel-phprdkafka](https://github.com/ensi-platform/laravel-php-rdkafka)

Then,

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

Publish the config file with:

```
php artisan vendor:publish --provider="Ensi\LaravelPhpRdKafkaConsumer\LaravelPhpRdKafkaConsumerServiceProvider" --tag="kafka-consumer-config"
```

Now go to `config/kafka-consumer.php` and add processors there.

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

[](#version-compatibility)

Laravel rdkakfa-consumerLaravelPHPensi/laravel-phprdkafka^0.1.0^7.x || ^8.x^8.0^0.1.4^0.2.0^7.x || ^8.x^8.0^0.1.4^0.2.1^7.x || ^8.x^8.0^0.2^0.2.5^8.x || ^9.x^8.0^0.2^0.3.0^8.x || ^9.x^8.0^0.3^0.3.2^8.x || ^9.x || ^10.x^8.0^0.3^1.0.0^8.x || ^9.x^8.0^0.3^2.0.0^10.x || ^11.x^8.1^0.3^2.0.1^10.x || ^11.x^8.1^0.4.0^2.0.8^10.x || ^11.x || ^12.x^8.1^0.4.5Basic Usage
-----------

[](#basic-usage)

The package provides `php artisan kafka:consume {topic} {consumer=default} {--max-events=0} {--max-time=0} {--once}` command that executes the first processor that matches given topic and consumer name. Consumer name is taken from `ensi/laravel-phprdkafka config` file.

Processors in config have the following configuration options:

```
[
   /*
   | Optional, defaults to `null`.
   | Here you may specify which topic should be handled by this processor.
   | Processor handles all topics by default.
   */
   'topic' => 'stage.crm.fact.registrations.1',

   /*
   | Optional, defaults to `null`.
   | Here you may specify which ensi/laravel-phprdkafka consumer should be handled by this processor.
   | Processor handles all consumers by default.
   */
   'consumer' => 'default',

   /*
   | Optional, defaults to `action`.
   | Here you may specify processor's type. Defaults to `action`
   | Supported types:
   |  - `action` - a simple class with execute method;
   |  - `job` - Laravel Queue Job. It will be dispatched using `dispatch` or `dispatchSync` method;
   */
   'type' => 'action',

   /*
   | Required.
   | Fully qualified class name of a processor class.
   */
   'class' => \App\Domain\Communication\Actions\SendConfirmationEmailAction::class,

   /*
   | Optional, defaults to `false`.
   | Proxy messages to Laravel's queue.
   | Supported values:
   |  - `false` - do not stream message. Execute processor in syncronous mode;
   |  - `true` - stream message to Laravel's default queue;
   |  - `` - stream message to this queue;
   */
   'queue' => false,

   /*
   | Optional, defaults to 5000.
   | Kafka consume timeout in milliseconds .
   */
   'consume_timeout' => 5000,
]
```

**Important!** Some topics have to have different consumer settings, such as start reading topic from the beginning or don't create topic if it is not exists yet.
For such cases you need to configure several consumers and use suitable one.

### Synchronous processors

[](#synchronous-processors)

Most of the time all tou need is a synchronous processor. A simple example of such processor:

```
use RdKafka\Message;

class SendConfirmationEmailAction
{
   public function execute(Message $message): void
   {
      // var_dump($message->payload);
   }
}
```

### Queueable processors

[](#queueable-processors)

If you want to stream message to Laravel's own queue you can use [spatie/laravel-queueable-action](https://github.com/spatie/laravel-queueable-action)

If for some reason you don't want to rely on that package you can swich to [Laravel Jobs](https://laravel.com/docs/master/queues#class-structure)

In both cases you also need to specify `'queue' => true` or `'queue' => 'my-favorite-queue'` in the package's config for a given processor.

Processor using Laravel Job example:

```
use RdKafka\Message;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;

class ConsumeMessageJob implements ShouldQueue
{
   use Dispatchable, InteractsWithQueue, Queueable;

   public function __construct(protected Message $message)
   {
   }

   public function handle(): void
   {
      // var_dump($this->message->payload);
   }
}
```

### Handling signals

[](#handling-signals)

`php artisan kafka:consume ...` command can be configured to gracefully stop after receiving some OS signals.
Such signals can be set in the `stop_signals` key of the package config, e.g `'stop_signals' => [SIGINT, SIGQUIT]`.
You can use any of the constants defined by the pcntl extension

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

[](#contributing)

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

Consumer faking
---------------

[](#consumer-faking)

Testing tools have been added to test the developed handlers. You can create a fake Consumer and call the topic listening command:

```
use Ensi\LaravelPhpRdKafkaConsumer\Commands\KafkaConsumeCommand;
use Ensi\LaravelPhpRdKafkaConsumer\Tests\ConsumerFaker;
use RdKafka\Message;

ConsumerFaker::new(['test-model'])
    ->addMessage(new Message())
    ->addMessage(new Message())
    ->consume();
```

Testing
-------

[](#testing)

### Testing

[](#testing-1)

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

53

—

FairBetter than 97% of packages

Maintenance74

Regular maintenance activity

Popularity37

Limited adoption so far

Community18

Small or concentrated contributor base

Maturity69

Established project with proven stability

 Bus Factor1

Top contributor holds 58.7% 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 ~73 days

Recently: every ~78 days

Total

22

Last Release

146d ago

Major Versions

0.3.2 → 1.0.02024-05-07

1.0.0 → 2.0.02024-05-07

PHP version history (2 changes)0.1.0PHP ^8.0

2.0.1PHP ^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

[![MsNatali](https://avatars.githubusercontent.com/u/8089373?v=4)](https://github.com/MsNatali "MsNatali (27 commits)")[![popkovkirill](https://avatars.githubusercontent.com/u/6718174?v=4)](https://github.com/popkovkirill "popkovkirill (5 commits)")[![C0rTeZ13](https://avatars.githubusercontent.com/u/120840631?v=4)](https://github.com/C0rTeZ13 "C0rTeZ13 (4 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 (1 commits)")[![amlagoda](https://avatars.githubusercontent.com/u/49432167?v=4)](https://github.com/amlagoda "amlagoda (1 commits)")

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[mpbarlow/laravel-queue-debouncer

A wrapper job for debouncing other queue jobs.

63714.4k1](/packages/mpbarlow-laravel-queue-debouncer)[eyewitness/eye

Eyewitness.io client for Laravel 5 applications

116151.8k](/packages/eyewitness-eye)[therezor/laravel-transactional-jobs

Submit laravel jobs inside transaction. Cancel job after rollback. Proceed after successful commit.

44449.4k](/packages/therezor-laravel-transactional-jobs)[convenia/pigeon

3233.0k](/packages/convenia-pigeon)[baklysystems/laravel-chat-messenger

Laravel chat package

121.8k](/packages/baklysystems-laravel-chat-messenger)

PHPackages © 2026

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