kafka-php icon indicating copy to clipboard operation
kafka-php copied to clipboard

How to stop consumer?

Open KlimTodrik opened this issue 6 years ago • 2 comments

How I can stop consumer now? I getting a looping script which working all the time, but what if I need to stop that? Of course, I can write some script that will find PHP process and kill that, but it will an ugly way.

KlimTodrik avatar Oct 21 '19 10:10 KlimTodrik

+1

tezhm avatar Jan 22 '20 04:01 tezhm

Found that internally the consumer is using Amp\Reactor which is generated as a singleton via Amp\reactor() method. This provides a couple of options:

  • Schedule a callback to ->stop() the reactor via reactor()->once(...), reactor()->repeat(...), or reactor()->immediately(...)
  • In the consumer callback, call reactor()->stop()
    • Main downside is that you have to wait for a message to be consumed before this code is called

tezhm avatar Jan 22 '20 04:01 tezhm