mateusjunges / laravel-kafka

Use Kafka Producers and Consumers in your laravel app with ease!
https://laravelkafka.com/docs/v2.0/introduction
MIT License
573 stars 81 forks source link

stopAfterLastMessage not working as expected. #301

Open henzeb opened 3 months ago

henzeb commented 3 months ago

Describe the bug stopAfterLastMessage does not work as expected. I expected it to consume all messages from the last offset it had consumed, but instead it just stops the process.

To Reproduce Steps to reproduce the behavior:

  1. create the topic test_topic
  2. publish a few messages to this topic
  3. now listen to this topic using the following code:
    Kafka::consumer()
            ->subscribe('test_topic')
            ->withMaxMessages(50)
            ->stopAfterLastMessage()
            ->withHandler(
                function(ConsumerMessage $message){
                    dump($message->getBody());
                }
            )->build()
            ->consume();

Expected behavior I expect to see the messages I sent in step 2 to show up and then the process ends.

Actual behavior Stops the process without even consuming the messages.

Additional context PHP 8.2 latest rdkafka extension version latest laravel-kafka version

henzeb commented 3 months ago

seems something to do with a timeout. setting consumer_timeout_ms to 4000 seems to work. Either this needs to be addressed in the documentation or the default timeout needs an increase.