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 makes it easy to produce and consume Kafka messages in Laravel with a clean, expressive API and improved testability. Build producers and consumers quickly, integrate with your app workflows, and avoid painful Kafka testing setups.

View on GitHub
Deep Wiki
Context7

Use Kafka Producers and Consumers in your laravel app with ease!

Frequently asked questions about Laravel Kafka
How do I replace Laravel’s database queues with Kafka using this package?
Use the `KafkaQueue` class to dispatch jobs via `dispatch()` or `dispatchNow()`. Configure your queue connection in `config/queue.php` to use `kafka` as the driver. Consumers are then run with `php artisan kafka:consume`, replacing `queue:work`. Ensure your Kafka broker is properly configured in the package’s config file.
Can I use Laravel Kafka for real-time event streaming between microservices?
Yes, this package is ideal for event-driven architectures. Produce events using `Kafka::produce()` and consume them in separate services via `KafkaConsumer` contracts. Leverage Laravel’s service container to inject consumers, and use topics to decouple services. For high throughput, consider partitioned consumers or batch processing.
What Laravel versions does Laravel Kafka support, and what’s the PHP requirement?
The package supports Laravel 10 and 11 as of June 2026. PHP 8.1 or higher is required. Ensure your `composer.json` specifies compatible Laravel and PHP versions to avoid dependency conflicts. Check the [documentation](https://laravelkafka.com/) for version-specific setup instructions.
How do I mock Kafka consumers for unit testing in Laravel?
Use the built-in `FakeBuilder` to simulate Kafka topics and messages. In your test, call `Kafka::fake()` to disable real Kafka interactions. Assert produced messages with `Kafka::assertProduced()` or mock consumers with `KafkaConsumer::fake()`. This avoids needing a local Kafka cluster during tests, speeding up CI/CD pipelines.
Does Laravel Kafka support SASL/SSL authentication for cloud Kafka brokers like Confluent?
Yes, configure SASL/SSL in the `config/kafka.php` file under the `security_protocol`, `sasl_mechanism`, and `ssl` sections. For Confluent Cloud, specify `SASL_SSL` as the protocol, `PLAIN` or `SCRAM-SHA-256` for SASL, and provide the required credentials. Test connectivity with `kafka:produce` or `kafka:consume` before deploying.
How can I handle dead-letter queues (DLQ) for failed Kafka message processing?
Configure a DLQ topic in your consumer’s `handle()` method or via the `kafka:consume` command with `--dlq-topic`. Failed messages are automatically routed to the DLQ if exceptions occur. Monitor the DLQ topic separately and implement retry logic or alerts for poison pills. Use `max.poll.interval.ms` to avoid consumer timeouts.
Is it possible to integrate Laravel Kafka with Laravel Echo for real-time updates?
No, Laravel Kafka is designed for async message processing, not real-time WebSocket broadcasting. For real-time updates, use Laravel Echo with Pusher or Ably. However, you can combine Kafka for async event processing (e.g., notifications) and Echo for live UI updates by triggering Echo events from Kafka consumers.
What are the performance implications of using Kafka vs. Laravel’s database queues?
Kafka offers higher throughput and lower latency for async tasks compared to database queues, especially for high-volume workloads. However, Kafka requires a stable broker cluster and adds operational complexity (e.g., offset management, consumer groups). Benchmark your use case: Kafka excels for event sourcing or microservices, while database queues may suffice for simple background jobs.
How do I scale Kafka consumers horizontally in a Laravel deployment?
Scale consumers by running multiple `kafka:consume` processes with unique consumer group IDs. Use Kafka’s partition key to distribute messages evenly. For stateful consumers, offload session data to Redis or a database. Monitor consumer lag with tools like `kafka-consumer-groups` or custom metrics. Avoid sticky sessions unless necessary for ordering guarantees.
Are there alternatives to Laravel Kafka for Kafka integration in Laravel?
Alternatives include `php-kafka/ext-rdkafka` (low-level bindings) or `reactphp/kafka` (reactive streams). However, these lack Laravel-specific features like queue integration, testing tools, or expressive syntax. Laravel Kafka stands out for its seamless Laravel integration, including facade support, queue compatibility, and built-in testing utilities. Evaluate your needs: raw performance vs. developer ergonomics.
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.
codraw/framework-extra-bundle
codraw/messenger
codraw/security
codraw/mailer
codraw/contracts
codraw/profiling
codraw/dependency-injection
codraw/tester
codraw/core
nexmo/api-specification
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony