mateusjunges/laravel-kafka
Laravel Kafka brings a clean Laravel-friendly API for producing and consuming Kafka messages, with an emphasis on developer experience and easier testing. Ideal for integrating Kafka streams and event-driven workflows into your Laravel applications.
Kafka::publish()->onTopic()->withBody()), making it a natural fit for:
fake() for unit tests). The facade-based API aligns with Laravel’s conventions (e.g., Queue::dispatch()).confluentinc/cp-schema-registry)..env).rdkafka (librdkafka) under the hood, which may require native extensions (PECL) or Dockerized Kafka clusters for local dev. Risk: CI/CD complexity if not containerized.fetch.max.bytes).shouldReceiveMessages) is powerful but may not cover real-world edge cases (e.g., offset commits, retries).confluentinc/schema-registry).config/services.php.Kafka::publish()/Kafka::consume() mirror Laravel’s Queue:: syntax.user.created).Kafka::fake(), reducing need for external mocking tools.OrderCreated → Kafka topic).ProcessPodcastUpload → Kafka listener).ext-json (default) and optionally ext-rdkafka (for native performance).composer require mateusjunges/laravel-kafka
php artisan vendor:publish --provider="Junges\Kafka\KafkaServiceProvider"
.env:
KAFKA_BROKERS=localhost:9092
KAFKA_DEFAULT_TOPIC=default-topic
Kafka::publish('broker')
->onTopic('orders.created')
->withBody(['order_id' => 123])
->send();
Kafka::consume(['orders.created'])
->withHandler(function ($message) {
// Process order
})
->build()
->consume();
Kafka::fake() for unit tests.sasl.mechanism).storage/logs/laravel-kafka.log by default. Centralize logs for production.Kafka::publish()->send() return values for errors.How can I help you explore Laravel packages today?