PHPackages                             siberfx/apache-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. siberfx/apache-kafka

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

siberfx/apache-kafka
====================

Apache Kafka Service Helper

0.3.0(2w ago)13MITPHPPHP ^8.4CI failing

Since Oct 20Pushed 2w ago1 watchersCompare

[ Source](https://github.com/siberfx/kafka-queue)[ Packagist](https://packagist.org/packages/siberfx/apache-kafka)[ Docs](https://github.com/siberfx/apache-kafka)[ RSS](/packages/siberfx-apache-kafka/feed)WikiDiscussions main Synced today

READMEChangelog (5)Dependencies (3)Versions (6)Used By (0)

Apache Kafka Queue Service for Laravel 12.x 13.x

[](#apache-kafka-queue-service-for-laravel-12x-13x)

A Laravel queue driver backed by [Apache Kafka](https://kafka.apache.org/) (tested against [Confluent Cloud](https://www.confluent.io/)). It lets you dispatch Laravel jobs to a Kafka topic and process them with the standard `queue:work` worker.

Requirements
------------

[](#requirements)

- PHP `^8.4`
- Laravel `^12.0 | ^13.0`
- The [`rdkafka`](https://github.com/arnaud-lb/php-rdkafka) PHP extension (built on top of [`librdkafka`](https://github.com/confluentinc/librdkafka))
- A reachable Kafka cluster (self-hosted or Confluent Cloud)

Required before starting
------------------------

[](#required-before-starting)

If you are using Confluent Cloud, create an account at , create a new project and provision an "Apache Kafka on Confluent Cloud" cluster, then create an API key/secret that will be used as the SASL username/password below.

```
curl -L --http1.1 https://cnfl.io/ccloud-cli | sh -s -- -b /usr/local/bin
```

[![img_1.png](img/img_1.png)](img/img_1.png)[![img_2.png](img/img_2.png)](img/img_2.png)

Make sure the `rdkafka` extension is installed and enabled before installing the package:

[![img_1.png](img/img_3.png)](img/img_3.png)

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

[](#installation)

### 1. Install the `rdkafka` PHP extension

[](#1-install-the-rdkafka-php-extension)

```
# install librdkafka first (Debian/Ubuntu)
sudo apt-get update && sudo apt-get install -y librdkafka-dev

# then the PHP extension
pecl install rdkafka

# enable it (add to your php.ini)
echo "extension=rdkafka.so" >> "$(php -i | grep -i 'Loaded Configuration File' | awk '{print $5}')"
```

> A ready-to-use container is provided under [`docker/`](docker/) (PHP 8.4 with `librdkafka` and `rdkafka` already compiled). Run it with `docker compose -f docker/docker-compose.yaml up`.

### 2. Require the package via Composer

[](#2-require-the-package-via-composer)

```
composer require siberfx/apache-kafka
```

The service provider (`Siberfx\Kafka\KafkaServiceProvider`) is auto-discovered — no manual registration required.

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

[](#configuration)

### 1. Add a `kafka` connection to `config/queue.php`

[](#1-add-a-kafka-connection-to-configqueuephp)

The connector reads its settings from the queue connection config. Add the following entry under `connections`:

```
'connections' => [

    // ...

    'kafka' => [
        'driver'            => 'kafka',
        'bootstrap_servers' => env('KAFKA_BROKERS', 'localhost:9092'),
        'security_protocol' => env('KAFKA_SECURITY_PROTOCOL', 'SASL_SSL'),
        'sasl_mechanisms'   => env('KAFKA_SASL_MECHANISMS', 'PLAIN'),
        'sasl_username'     => env('KAFKA_SASL_USERNAME', ''),
        'sasl_password'     => env('KAFKA_SASL_PASSWORD', ''),
        'group_id'          => env('KAFKA_GROUP_ID', 'laravel'),
    ],

],
```

### 2. Set your `.env`

[](#2-set-your-env)

```
QUEUE_CONNECTION=kafka

# default topic used when a job does not specify one
KAFKA_QUEUE=default

KAFKA_BROKERS=pkc-xxxxx.region.provider.confluent.cloud:9092
KAFKA_SECURITY_PROTOCOL=SASL_SSL
KAFKA_SASL_MECHANISMS=PLAIN
KAFKA_SASL_USERNAME=your-api-key
KAFKA_SASL_PASSWORD=your-api-secret
KAFKA_GROUP_ID=laravel-consumers
```

> For a local, unauthenticated broker use `KAFKA_SECURITY_PROTOCOL=PLAINTEXT` and leave the SASL values empty.

### 3. (Optional) Publish the package config

[](#3-optional-publish-the-package-config)

```
php artisan vendor:publish --provider="Siberfx\Kafka\KafkaServiceProvider" --tag=config
```

This publishes `config/kafka-config.php`, which you can use to hold your own Kafka-related values. Note that the queue **driver** itself is configured from `config/queue.php` (step 1).

Usage
-----

[](#usage)

### Define a job

[](#define-a-job)

```
