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.
You can call pre-defined callbacks Before and After consuming messages. As an example, you can use this to make your consumer to wait while in maintenance mode.
The callbacks get executed in the order they are defined, and they receive a \Junges\Kafka\Contracts\MessageConsumer as argument:
$consumer = \Junges\Kafka\Facades\Kafka::consumer()
->beforeConsuming(function(\Junges\Kafka\Contracts\MessageConsumer $consumer) {
while (app()->isDownForMaintenance()) {
sleep(1);
}
})
->afterConsuming(function (\Junges\Kafka\Contracts\MessageConsumer $consumer) {
// Runs after consuming the message
})
These callbacks are not middlewares, so you can not interact with the consumed message. You can add as many callback as you need, so you can divide different tasks into different callbacks.
<x-sponsors.request-sponsor/>
How can I help you explore Laravel packages today?