Before and after callbacks
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.
Support Laravel Kafka by sponsoring me!
Do you find Laravel Kafka valuable and wanna support its development?
Laravel Kafka is free and Open Source software, built to empower developers like you. Your support helps maintain and enhance the project. If you find it valuable, please consider sponsoring me on GitHub. Every contribution makes a difference and keeps the development going strong! Thank you!