0

I am very confused. So any help it will be very wellcome. I am trying to deploy a lumen app, that can consume message from kafka.

I have gueesed that queue could be the right apporach to the problem, but i cannot find a path to solve the problem.

I have found this lib: https://github.com/php-enqueue/enqueue-dev/blob/master/docs/laravel/quick_tour.md

that is saying that the message can be consumed by call:

php artisan enqueue:consume -vvv --setup-broker

that is putting me in confusion, because to me now is not clear how to use it inside my functions, or having an async listener to a specific external kafka service.

JahStation
  • 893
  • 3
  • 15
  • 35

1 Answers1

0

That command seems to be from the CLI, not a deployed PHP application.

The Enqueue Kafka connector docs are here - https://php-enqueue.github.io/transport/kafka/#consume-message

Snippet

$fooQueue = $context->createQueue('foo');

$consumer = $context->createConsumer($fooQueue);

// Enable async commit to gain better performance (true by default since version 0.9.9).
//$consumer->setCommitAsync(true);

$message = $consumer->receive();

// process a message

$consumer->acknowledge($message);
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
  • thanks, so this piece of code needs to be insert in event?or as classic route/controller? do i need something like a lock while(true){} – JahStation Feb 15 '22 at 08:53
  • You'll probably need a loop around the receive and acknowledge calls, yes. I wouldn't put a consumer in the execution path of any http route since http clients have timeouts and there's no guarantee kafka consumers will ever read any data (you would need to put your own timeouts on any consumer loops) – OneCricketeer Feb 15 '22 at 13:56