PHPackages                             nirmalsharma/laravel-kafka-php - 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. [API Development](/categories/api)
4. /
5. nirmalsharma/laravel-kafka-php

ActiveLibrary[API Development](/categories/api)

nirmalsharma/laravel-kafka-php
==============================

0.0.3(3y ago)0125MITPHPPHP &gt;=7.2

Since Jan 10Pushed 3y ago2 watchersCompare

[ Source](https://github.com/nirmalsharmamca/laravel-kafka-php)[ Packagist](https://packagist.org/packages/nirmalsharma/laravel-kafka-php)[ RSS](/packages/nirmalsharma-laravel-kafka-php/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)DependenciesVersions (5)Used By (0)

A Lightweight Kafka wrapper for Laravel 6+ and PHP 7.3+
-------------------------------------------------------

[](#a-lightweight-kafka-wrapper-for-laravel-6-and-php-73)

Install Kafka wrapper

```
  composer require nirmalsharma/laravel-kafka-php
```

Examples
--------

[](#examples)

[Laravel 6](examples/laravel-6)

Use Kafka producer in code.
---------------------------

[](#use-kafka-producer-in-code)

Add following in web.php

```
use KafkaProducer;

$topic = "kafka-topic";
$data = [
    "user_ref" => "usr.123456",
    "message" => "Hello World"
];
$key = "usr.123456"; // Optional, Default null
$headers = [
    "ContentType" => "application/json",
    "Timezone" => "GMT +05:30"
]; // Optional
KafkaProducer::push($topic, $data, $key, $headers);
```

Use Kafka consumer in code.
---------------------------

[](#use-kafka-consumer-in-code)

KafkaConsumer code for console

```
namespace App\Console\Commands;

use App\Handlers\TestHandler;
use Illuminate\Console\Command;
use KafkaConsumer;

class TestTopicConsumer extends Command
{
    protected $signature = 'kafka:test-consume {--partition=} {--consumer-group=} {--topic=} {--dlq-topic=}';

    protected $description = 'Kafka consumer!!';

    public function handle(): void
    {
      KafkaConsumer::createConsumer(new TestHandler);
    }

    public function setKafkaConfig(){
      $partition = $this->option('partition');
      if( $partition != null){
          config([
              "kafka.partition" => $partition
          ]);
      }

      $consumer_group_id = $this->option('consumer-group');
      if( !empty($consumer_group_id)){
          config([
              "kafka.consumer_group_id" => $consumer_group_id
          ]);
      }

      $topic = $this->option('topic');
      if( !empty($topic)){
          config([
              "kafka.topic" => $topic
          ]);
      }

      $dlq_topic = $this->option('dlq-topic');
      if( !empty($dlq_topic)){
          config([
              "kafka.dlq_topic" => $dlq_topic
          ]);
      }
    }
}

TestHandler.php
-----------------

namespace App\Handlers;

use Illuminate\Support\Facades\Log;

class TestHandler
{
  public function __invoke( $message)
  {
    dump([
      "partition" => $message['raw']->partition,
      "key" => $message['key']
    ]);
  }
}
```

To start listening messages by run following command:
-----------------------------------------------------

[](#to-start-listening-messages-by-run-following-command)

```
  php artisan kafka:test-consume --consumer-group=test-local --topic=demo-topic --dlq-topic=demo-dlq

```

You can use KafkaConsumerException for business logic or consumer handler logic to send message forcefully in DLQ
-----------------------------------------------------------------------------------------------------------------

[](#you-can-use-kafkaconsumerexception-for-business-logic-or-consumer-handler-logic-to-send-message-forcefully-in-dlq)

```
  use Nirmalsharma\LaravelKafkaPhp\Exceptions\KafkaConsumerException;

  throw new KafkaConsumerException('Not valid.');

```

Environment Variables
---------------------

[](#environment-variables)

To run this, you will need to add the following environment variables to your .env file Config reference:

```
IS_KAFKA_ENABLED=             // Default:  1
KAFKA_BROKERS=
KAFKA_DEBUG=                  // Default: false
KAFKA_SSL_PROTOCOL=           // Default: plaintext
KAFKA_COMPRESSION_TYPE=       // Default: none
KAFKA_IDEMPOTENCE=            // Default: false
KAFKA_CONSUMER_GROUP_ID=
KAFKA_OFFSET_RESET=           // Default: latest
KAFKA_AUTO_COMMIT=            // Default: true
KAFKA_DEBUG=false
KAFKA_DLQ_TOPIC=
KAFKA_TOPIC=

```

Authors
-------

[](#authors)

- [Nirmal Sharma](https://github.com/nirmalsharmamca)
- [Praveen Menezes](https://github.com/praveenmenezes)

License
-------

[](#license)

[MIT](https://choosealicense.com/licenses/mit/)

Features
--------

[](#features)

- Light weight kakfa wrapper
- Easy to produce kafka event and consume in php.

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity34

Early-stage or recently created project

 Bus Factor1

Top contributor holds 76.9% 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 ~0 days

Total

3

Last Release

1219d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/b73872f148a595a3893c4f43684add3758f50e16408167d98876c4ab9714610e?d=identicon)[nirmalsharmamca](/maintainers/nirmalsharmamca)

---

Top Contributors

[![nirmalkissht](https://avatars.githubusercontent.com/u/118504956?v=4)](https://github.com/nirmalkissht "nirmalkissht (10 commits)")[![praveen-kissht](https://avatars.githubusercontent.com/u/156430945?v=4)](https://github.com/praveen-kissht "praveen-kissht (2 commits)")[![praveenmenezes](https://avatars.githubusercontent.com/u/10197721?v=4)](https://github.com/praveenmenezes "praveenmenezes (1 commits)")

### Embed Badge

![Health badge](/badges/nirmalsharma-laravel-kafka-php/health.svg)

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

###  Alternatives

[stripe/stripe-php

Stripe PHP Library

4.0k143.3M480](/packages/stripe-stripe-php)[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M272](/packages/twilio-sdk)[knplabs/github-api

GitHub API v3 client

2.2k15.8M187](/packages/knplabs-github-api)[facebook/php-business-sdk

PHP SDK for Facebook Business

90121.9M34](/packages/facebook-php-business-sdk)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

73813.7M114](/packages/meilisearch-meilisearch-php)[google/gax

Google API Core for PHP

263103.1M454](/packages/google-gax)

PHPackages © 2026

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