Download the PHP package opennebel/laravel-kafka without Composer
On this page you can find all versions of the php package opennebel/laravel-kafka. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download opennebel/laravel-kafka
More information about opennebel/laravel-kafka
Files in opennebel/laravel-kafka
Package laravel-kafka
Short Description A Laravel wrapper around php-rdkafka to produce Kafka messages easily.
License MIT
Informations about the package laravel-kafka
LaravelKafka
LaravelKafka is a simple yet powerful library for producing messages to Apache Kafka from your Laravel applications. It builds upon php-rdkafka and adheres to Laravel conventions, including Service Providers, Facades, Queueable Jobs, Artisan commands, dependency injection, and configuration.
๐ง Maintained by OpenNebel
๐งฉ Features
- โ Synchronous Kafka message sending
- ๐ Asynchronous support via Laravel's queue system
- ๐งฑ Modular structure (producers, config, jobs, DLQ)
- ๐ง Support for headers, keys, partitions, msgflags
- ๐ Error handling (Dead Letter Queue with full Kafka options)
- ๐งช Integrated Artisan commands (
status
,retry-failed
) - ๐ฆ Compatible with Laravel Horizon, Telescope, Docker, CI/CD
๐ Installation
1. Install the PHP Kafka extension
๐ Ensure
php.ini
loads the extension:extension=rdkafka
2. Install the library
โ๏ธ Configuration
Method 1 โ Full Publication (config + migration)
Method 2 โ Separate Publication
.env
File
โ๏ธ Sending Messages
๐น Synchronous Sending
๐ธ Asynchronous Sending (Laravel Queue)
Start the worker to process jobs:
๐งฉ Usage with Dependency Injection
๐ฅ Error Handling (DLQ)
If flush()
fails or the broker is unreachable, the message is:
- recorded in the
kafka_failed_messages
table - all Kafka
options
are stored as JSON - accessible via Artisan command
- manually re-attemptable
Migration:
Retry Failed Messages:
๐ Artisan Commands
Command | Description |
---|---|
kafka:status |
Checks Kafka broker connectivity and lists metadata |
kafka:retry-failed |
Retries messages in the DLQ |
These commands are auto-registered via KafkaServiceProvider
.
๐งฐ Service API
Method | Description |
---|---|
produce() |
Raw string to topic with optional headers/key/partition/msgflags |
produceJson() |
JSON payload to topic |
produceToDefault() |
Raw string to default topic |
produceJsonToDefault() |
JSON payload to default topic |
produceAsync() |
Dispatch async job to a topic |
produceAsyncToDefault() |
Dispatch async job to default topic |
flush($timeoutMs) |
Flush local queue to Kafka broker |
getQueueLength() |
Messages in local Kafka buffer |
ping() |
Kafka connection test |
getMetadata() |
Cluster info: topics, partitions, brokers |
isConnected() |
Indicates producer was created correctly |
๐ Configuration (config/kafka.php
)
โ Prerequisites
- PHP >= 8.0
- Laravel >= 9.x
ext-rdkafka
PHP extension- Kafka broker (local, Docker, or cloud)
๐ง Recommendations
- Use Laravel Horizon to manage async jobs
- Monitor failures with Telescope or Sentry
- Track Kafka logs via
storage/logs/laravel.log
๐ License
MIT ยฉ OpenNebel