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

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

smartcoder01/laravel-queue-kafka
================================

This is a Laravel queue adapter for the Kafka.

1.0(1y ago)051MITPHP

Since Mar 22Pushed 1y ago1 watchersCompare

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

READMEChangelog (1)Dependencies (3)Versions (2)Used By (0)

Laravel Kafka Queue Driver
==========================

[](#laravel-kafka-queue-driver)

This package provides a Kafka-based queue driver for Laravel, allowing you to use Apache Kafka as a message queue for your Laravel applications. It integrates seamlessly with Laravel's queue system, enabling you to push jobs to Kafka and process them using Kafka consumers.

---

Features
--------

[](#features)

- **Kafka Queue Driver**: Use Kafka as a queue driver in Laravel.
- **Producer and Consumer Support**: Easily produce and consume messages from Kafka topics.
- **Configuration**: Customize Kafka connection settings via Laravel's configuration files.
- **Service Provider**: Automatically registers Kafka connectors and dependencies.
- **Job Handling**: Process jobs using Laravel's job handling system.

---

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

[](#installation)

You can install the package via Composer:

```
composer require smartcoder01/laravel-kafka-queue
```

---

Configuration
-------------

[](#configuration)

### 1. Publish Configuration File

[](#1-publish-configuration-file)

Publish the configuration file to your Laravel application:

```
php artisan vendor:publish --provider="Smartcoder01\Queue\Kafka\KafkaQueueServiceProvider"
```

This will create a `kafka.php` file in your `config` directory.

### 2. Update `.env`

[](#2-update-env)

Add the following Kafka configuration to your `.env` file:

```
QUEUE_CONNECTION=kafka

KAFKA_BROKER_LIST=localhost:9092
KAFKA_GROUP_ID=laravel-queue-group
KAFKA_AUTO_OFFSET_RESET=earliest
KAFKA_QUEUE=default
```

### 3. Configure Kafka Connection

[](#3-configure-kafka-connection)

Update the `config/kafka.php` file to match your Kafka setup:

```
return [
    'connections' => [
        'kafka' => [
            'broker_list' => env('KAFKA_BROKER_LIST', 'localhost:9092'),
            'group_id' => env('KAFKA_GROUP_ID', 'laravel-queue-group'),
            'auto_offset_reset' => env('KAFKA_AUTO_OFFSET_RESET', 'earliest'),
            'queue' => env('KAFKA_QUEUE', 'default'),
            'default_configuration' => [
                'enable.auto.commit' => 'true',
                // Add other Kafka configuration options here
            ],
        ],
    ],
];
```

---

Usage
-----

[](#usage)

### 1. Setting Up Queues

[](#1-setting-up-queues)

To use Kafka as your queue driver, update the `QUEUE_CONNECTION` variable in your `.env` file:

```
QUEUE_CONNECTION=kafka
```

### 2. Pushing Jobs to Kafka

[](#2-pushing-jobs-to-kafka)

You can push jobs to Kafka just like you would with any other Laravel queue driver:

```
dispatch(new \App\Jobs\ProcessOrder($order));
```

Alternatively, you can use the `Queue` facade:

```
use Illuminate\Support\Facades\Queue;

Queue::push(new \App\Jobs\ProcessOrder($order));
```

### 3. Consuming Jobs

[](#3-consuming-jobs)

To process jobs from Kafka, run the Laravel queue worker:

```
php artisan queue:work
```

This will start a worker that listens to the Kafka topic specified in your configuration.

---

Advanced Configuration
----------------------

[](#advanced-configuration)

### Customizing Kafka Producer and Consumer

[](#customizing-kafka-producer-and-consumer)

You can customize the Kafka producer and consumer by modifying the `registerDependencies` method in the `KafkaQueueServiceProvider`:

```
$this->app->bind('queue.kafka.producer', function ($app, $parameters) {
    $conf = new \RdKafka\Conf();
    $conf->set('metadata.broker.list', env('KAFKA_BROKER_LIST', 'localhost:9092'));
    return new \RdKafka\Producer($conf);
});

$this->app->bind('queue.kafka.consumer', function ($app, $parameters) {
    $conf = new \RdKafka\Conf();
    $conf->set('metadata.broker.list', env('KAFKA_BROKER_LIST', 'localhost:9092'));
    $conf->set('group.id', env('KAFKA_GROUP_ID', 'laravel-queue-group'));
    $conf->set('auto.offset.reset', env('KAFKA_AUTO_OFFSET_RESET', 'earliest'));
    return new \RdKafka\KafkaConsumer($conf);
});
```

### Handling Deadlocks

[](#handling-deadlocks)

The package includes basic deadlock handling for job processing. If a deadlock is detected, the worker will retry the job after a short delay.

---

Troubleshooting
---------------

[](#troubleshooting)

### 1. Kafka Broker Not Reachable

[](#1-kafka-broker-not-reachable)

Ensure that your Kafka broker is running and accessible. Check the `KAFKA_BROKER_LIST` configuration in your `.env` file.

### 2. Consumer Not Receiving Messages

[](#2-consumer-not-receiving-messages)

- Verify that the `group.id` and `auto.offset.reset` settings are correct.
- Ensure that the Kafka topic exists and that the consumer is subscribed to the correct topic.

### 3. Producer Timeout

[](#3-producer-timeout)

If the producer times out while waiting for acknowledgment, increase the timeout in the `waitForAck` method:

```
protected function waitForAck()
{
    $timeout = 30 * 1000; // Increase timeout to 30 seconds
    // ...
}
```

---

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

[](#contributing)

Contributions are welcome! Please open an issue or submit a pull request if you have any improvements or bug fixes.

---

License
-------

[](#license)

This package is open-source software licensed under the [MIT License](LICENSE).

---

Credits
-------

[](#credits)

- [SmartCoder01](https://github.com/SmartCoder01)
- [Laravel](https://laravel.com)
- [php-rdkafka](https://github.com/arnaud-lb/php-rdkafka)

---

Enjoy using Kafka with Laravel! 🚀

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance45

Moderate activity, may be stable

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity37

Early-stage or recently created project

 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

Unknown

Total

1

Last Release

422d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/46fec9c3793ea4b0d0dbf6b4273f09526ccb22309332d8880de9986ce036eda4?d=identicon)[smartcoder01](/maintainers/smartcoder01)

---

Top Contributors

[![smartcoderpro-glitch](https://avatars.githubusercontent.com/u/265245777?v=4)](https://github.com/smartcoderpro-glitch "smartcoderpro-glitch (1 commits)")

---

Tags

laravelqueuekafka

### Embed Badge

![Health badge](/badges/smartcoder01-laravel-queue-kafka/health.svg)

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

###  Alternatives

[imtigger/laravel-job-status

Laravel Job Status

5272.1M3](/packages/imtigger-laravel-job-status)

PHPackages © 2026

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