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.
Sometimes, you may want to stop your consumer based on a given message or any other condition.
You can do it by adding a calling stopConsuming() method on the MessageConsumer instance that is passed as the
second argument of your message handler:
$consumer = \Junges\Kafka\Facades\Kafka::consumer(['topic'])
->withConsumerGroupId('group')
->stopAfterLastMessage()
->withHandler(static function (\Junges\Kafka\Contracts\ConsumerMessage $message, \Junges\Kafka\Contracts\MessageConsumer $consumer) {
if ($someCondition) {
$consumer->stopConsuming();
}
})
->build();
$consumer->consume();
The onStopConsuming callback will be executed before stopping your consumer.
<x-sponsors.request-sponsor/>
How can I help you explore Laravel packages today?