This is the documentation for
v1.11 but the latest version is
v1.13
.
You can switch versions in the menu on the left/at the top.
Check your current version with the following command:
composer show mateusjunges/laravel-kafka
Stopping consumers is very useful if you want to ensure you don't kill a process halfway through processing a consumed message.
To stop the consumer gracefully call the stopConsume
method on a consumer instance.
This is particularly useful when using signal handlers.
function gracefulShutdown(Consumer $consumer) {
$consumer->stopConsume(function() {
echo 'Stopped consuming';
exit(0);
});
}
$consumer = Kafka::createConsumer(['topic'])
->withConsumerGroupId('group')
->withHandler(new Handler)
->build();
pcntl_signal(SIGINT, fn() => gracefulShutdown($consumer));
$consumer->consume();
You will require the Process Control Extension to be installed to utilise the pcntl
methods.