PHPackages                             nassirian/laravel-kafka-migration - 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. [Database &amp; ORM](/categories/database)
4. /
5. nassirian/laravel-kafka-migration

ActiveLibrary[Database &amp; ORM](/categories/database)

nassirian/laravel-kafka-migration
=================================

Manage Kafka topics like Laravel migrations — create, migrate, and rollback Kafka topics with artisan commands.

v0.0.1(3mo ago)06↓90%MITPHPPHP ^8.1CI passing

Since Mar 25Pushed 3mo agoCompare

[ Source](https://github.com/nassirian/laravel-kafka-migration)[ Packagist](https://packagist.org/packages/nassirian/laravel-kafka-migration)[ Docs](https://github.com/nassirian/laravel-kafka-migration)[ RSS](/packages/nassirian-laravel-kafka-migration/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependencies (8)Versions (2)Used By (0)

Laravel Kafka Migration
=======================

[](#laravel-kafka-migration)

[![Tests](https://github.com/nassirian/laravel-kafka-migration/actions/workflows/tests.yml/badge.svg)](https://github.com/nassirian/laravel-kafka-migration/actions/workflows/tests.yml)[![Latest Version on Packagist](https://camo.githubusercontent.com/e0c0a55202512a64580952a219ede5f80317c2633b19e794140bf17789c04575/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6e617373697269616e2f6c61726176656c2d6b61666b612d6d6967726174696f6e2e737667)](https://packagist.org/packages/nassirian/laravel-kafka-migration)[![PHP Version](https://camo.githubusercontent.com/1d4f8baa8e97074acd1341413d51c08d20bc1a4cad51f8876b5e839c8b0ddee7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6e617373697269616e2f6c61726176656c2d6b61666b612d6d6967726174696f6e2e737667)](https://packagist.org/packages/nassirian/laravel-kafka-migration)[![License](https://camo.githubusercontent.com/a871d28d2ea81f46e103d902196d0f6b35a6f72a3289349dc3ba2393102b3d42/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6e617373697269616e2f6c61726176656c2d6b61666b612d6d6967726174696f6e2e737667)](https://packagist.org/packages/nassirian/laravel-kafka-migration)

Manage Kafka topics like Laravel migrations — create, track, and rollback Kafka topics using familiar artisan commands.

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

[](#requirements)

- PHP 8.1+
- Laravel 10, 11, or 12

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

[](#installation)

```
composer require nassirian/laravel-kafka-migration
```

Publish the config:

```
php artisan vendor:publish --tag=kafka-migration-config
```

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

[](#configuration)

Set your Kafka connection in `.env`:

```
KAFKA_MIGRATION_DRIVER=longlang   # rdkafka | longlang | http | mock
KAFKA_BROKERS=localhost:9092
```

### Available Drivers

[](#available-drivers)

DriverDescriptionRequires`longlang`Pure PHP Kafka client (recommended)`composer require longlang/phpkafka``rdkafka`High-performance via PHP extension`pecl install rdkafka``jobcloud`Fluent rdkafka wrapper by Jobcloud`composer require jobcloud/php-kafka-lib` + `ext-rdkafka``http`Confluent REST Proxy APIext-curl, REST Proxy running`mock`In-memory (for testing/development)NothingUsage
-----

[](#usage)

### Create a topic migration

[](#create-a-topic-migration)

```
php artisan make:kafka-topic orders
php artisan make:kafka-topic user-events
php artisan make:kafka-topic payment.processed
```

This creates a timestamped file in `database/kafka-migrations/`:

```
// database/kafka-migrations/2024_01_15_123456_create_orders_topic.php

use Nassirian\LaravelKafkaMigration\Migration\KafkaMigration;

return new class extends KafkaMigration
{
    public function up(): void
    {
        $this->createTopic(
            $this->topic('orders')
                ->partitions(3)
                ->replicationFactor(1)
                ->retentionMs(604_800_000)   // 7 days
                ->cleanupPolicy('delete')
                ->compressionType('snappy')
        );
    }

    public function down(): void
    {
        $this->deleteTopic('orders');
    }
};
```

### Topic builder options

[](#topic-builder-options)

```
$this->topic('my-topic')
    ->partitions(6)                     // number of partitions
    ->replicationFactor(3)              // replication factor
    ->retentionMs(604_800_000)          // retention in milliseconds
    ->retentionBytes(1_073_741_824)     // retention in bytes
    ->cleanupPolicy('delete')           // delete | compact | delete,compact
    ->compressionType('snappy')         // none | gzip | snappy | lz4 | zstd | producer
    ->minInsyncReplicas(2)              // min ISR
    ->maxMessageBytes(1_048_576)        // max message size
    ->segmentBytes(1_073_741_824)       // segment size
    ->config('custom.key', 'value');    // any raw Kafka config
```

### Run migrations

[](#run-migrations)

```
php artisan kafka:migrate
```

### Check status

[](#check-status)

```
php artisan kafka:migrate:status
```

### Rollback last batch

[](#rollback-last-batch)

```
php artisan kafka:migrate:rollback
php artisan kafka:migrate:rollback --step=2   # rollback 2 migrations
```

### Reset all migrations

[](#reset-all-migrations)

```
php artisan kafka:migrate:reset
```

### Pretend mode (dry run)

[](#pretend-mode-dry-run)

```
php artisan kafka:migrate --pretend
php artisan kafka:migrate:rollback --pretend
```

Using the Facade
----------------

[](#using-the-facade)

```
use Nassirian\LaravelKafkaMigration\Facades\KafkaManager;

KafkaManager::topicExists('orders');       // bool
KafkaManager::listTopics();                // string[]
KafkaManager::getTopicMetadata('orders');  // array

// Switch drivers at runtime
KafkaManager::driver('rdkafka')->listTopics();
```

Jobcloud Driver Details
-----------------------

[](#jobcloud-driver-details)

The `jobcloud` driver uses [`jobcloud/php-kafka-lib`](https://github.com/jobcloud/php-kafka-lib) as its configuration layer. That library provides a clean, opinionated fluent builder around `ext-rdkafka` — it handles broker normalisation, SASL, and SSL setup — and the package then hands off the resulting `KafkaConfiguration` (which extends `RdKafka\Conf`) directly to `RdKafka\AdminClient` for all topic operations.

```
KAFKA_MIGRATION_DRIVER=jobcloud
KAFKA_BROKERS=broker1:9092,broker2:9092

# Optional SASL
KAFKA_SECURITY_PROTOCOL=SASL_SSL
KAFKA_SASL_MECHANISMS=PLAIN
KAFKA_SASL_USERNAME=your-user
KAFKA_SASL_PASSWORD=your-pass

# Optional SSL
KAFKA_SSL_CA=/path/to/ca.pem
KAFKA_SSL_CERT=/path/to/cert.pem
KAFKA_SSL_KEY=/path/to/key.pem
```

Extra rdkafka settings can be passed via `extra_config` in `config/kafka-migration.php`:

```
'jobcloud' => [
    // ...
    'extra_config' => [
        'log_level'               => '6',
        'fetch.message.max.bytes' => '1048576',
    ],
],
```

Integration tests that require a live broker are tagged with `@group integration` and can be run separately:

```
composer test-integration
```

Registering a Custom Driver
---------------------------

[](#registering-a-custom-driver)

```
// In a service provider
use Nassirian\LaravelKafkaMigration\KafkaManager;

$this->app->make(KafkaManager::class)->extend('my-driver', function ($app) {
    return new MyCustomDriver($app['config']['kafka-migration.drivers.my-driver']);
});
```

Testing
-------

[](#testing)

Use the `mock` driver in your tests so no real Kafka connection is needed:

```
// config/kafka-migration.php  or  .env.testing
KAFKA_MIGRATION_DRIVER=mock
```

Run the test suite:

```
composer test
```

or

```
./vendor/bin/phpunit
```

License
-------

[](#license)

MIT

###  Health Score

32

—

LowBetter than 69% of packages

Maintenance82

Actively maintained with recent releases

Popularity4

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity32

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

93d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/5202490?v=4)[Iman Nassirian](/maintainers/nassirian)[@nassirian](https://github.com/nassirian)

---

Top Contributors

[![nassirian](https://avatars.githubusercontent.com/u/5202490?v=4)](https://github.com/nassirian "nassirian (11 commits)")

---

Tags

laravelmigrationqueuetopicskafka

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/nassirian-laravel-kafka-migration/health.svg)

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

###  Alternatives

[laravel/ai

The official AI SDK for Laravel.

9782.1M162](/packages/laravel-ai)[larastan/larastan

Larastan - Discover bugs in your code without running it. A phpstan/phpstan extension for Laravel

6.4k51.0M7.6k](/packages/larastan-larastan)[illuminate/queue

The Illuminate Queue package.

20432.2M1.5k](/packages/illuminate-queue)[psalm/plugin-laravel

Psalm plugin for Laravel

3345.1M337](/packages/psalm-plugin-laravel)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9742.3M121](/packages/roots-acorn)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)

PHPackages © 2026

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