Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Laravel Kafka

Laravel Kafka Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Laravel Kafka brings a clean, Laravel-friendly API for working with Apache Kafka, making it easier to produce and consume messages without the awkward syntax or painful testing workflows common in other packages. It’s built to fit naturally into Laravel projects while keeping integration and testability front and center.

Whether you’re publishing events or running consumers, Laravel Kafka provides a streamlined developer experience with solid tooling and clear documentation.

  • Elegant syntax for producing and consuming Kafka messages
  • Designed for testable Kafka workflows in Laravel
  • Integrates cleanly with typical Laravel application patterns
  • Actively maintained with CI and MIT license
Frequently asked questions about Laravel Kafka
How do I publish a Kafka message in Laravel using this package?
Use the fluent facade method `Kafka::publish()->onTopic('your-topic')->withBody(['key' => 'value'])->send()`. This follows Laravel’s idiomatic style and handles serialization automatically. For structured data, pair it with a schema registry like Avro or Protobuf.
Does Laravel Kafka support consuming messages from Kafka topics?
Yes, define a consumer class extending `KafkaConsumer` and register it in your `AppServiceProvider`. Use `Kafka::consume()` in a CLI command or queue worker. The package supports both polling and push-based consumption patterns.
What Laravel versions does this package support?
Laravel Kafka is designed for Laravel 10+ and requires PHP 8.1+. Check the [documentation](https://laravelkafka.com/) for version-specific setup instructions. The package aligns with Laravel’s latest conventions and testing tools.
Can I mock Kafka in unit tests without a real broker?
Absolutely. Use `Kafka::fake()` to simulate publishes and consumes in tests. This eliminates the need for Dockerized Kafka clusters during development, making unit testing as simple as mocking Laravel queues.
How does Laravel Kafka handle serialization? Can I use Avro or Protobuf?
By default, it uses JSON serialization. For Avro or Protobuf, integrate the `confluentinc/cp-schema-registry` package and configure a custom serializer in the package’s config. The package remains agnostic to schema formats.
Is this package suitable for high-throughput event processing (e.g., 1M+ messages/hour)?
Yes, but tuning may be required. Configure consumer groups, partitioning, and `fetch.max.bytes` in your `.env` for optimal performance. For extreme scale, pair it with Kafka Streams or KSQL for stream processing.
How do I handle failed message production or consumption?
The package uses exponential backoff for retries by default. For custom logic, implement `KafkaProducer::failed()` or `KafkaConsumer::failed()` callbacks. Failed messages can also be logged or dead-lettered via middleware.
Can I use Laravel Kafka alongside Laravel’s built-in queues?
Yes, it’s designed to complement or replace Laravel queues. Use Kafka for high-throughput async tasks (e.g., processing 10K+ events/hour) while keeping queues for simpler background jobs. Both can coexist in the same app.
What are the infrastructure requirements for running this package?
You’ll need a Kafka broker (self-hosted, Confluent Cloud, or AWS MSK) and the `rdkafka` PHP extension (PECL) for production. For local development, Dockerized Kafka clusters (e.g., Bitnami or Confluent images) simplify setup.
Are there alternatives to Laravel Kafka for Kafka in Laravel?
Other options include raw `rdkafka` PHP bindings or packages like `php-kafka/kafka`. However, Laravel Kafka stands out for its Laravel-native syntax, built-in testing support (`Kafka::fake()`), and seamless integration with Laravel’s service container and queues.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport