New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question: How to use consumer / producer in a web application #397
Comments
You're missing as import: use RdKafka\Conf; or global namespace prefix: $conf = new \RdKafka\Conf(); |
Bonjour
Merci beaucoup
Je pense que tout est resolu,. Je revien dans quelques minutes.
Compliments
Joao Faria
|
Bonsoir Nous avont des problemes avec le “consumer”, notament nous avons un probleme quando nous ne produisont un message.. Pouvez vous nous aider?? Nous envoyont un message du “response” Pardonnez mois le francais Producer
Consumer
Output
Merci bien |
Dear Joao Please don't use the low level consumer, it is overly complex and poses unnecessary challenges. I advice you to use the high level consumer ✌️ Cheers |
ok, i will try it thanks in advance |
With this code, the consumer laravel app dont show anything thanks for your attention |
@gordett if you see nothing at all (assign, waiting for assignment, etc.) it might be that you already have a consumer(s) running with the same consumer group. Imho even if you have no messages, after some point you should see |
Hello @nick-zh Me and @jfariablosis are implementing the above code. Thanks for your attention. Resume:
After run this code, i have the message in my browser. And in my kafka i can see a topic created , when i run this consumer
i only see the tab browser in loading, but if i remove the while (and continue and break) i can see this sorry for my big response, but i dont understanding why happens this... and maybe its a little change Thanks again |
As stated before, as a first step, please don't use the low level consumer. Also in the example you provided, you are writing to a different topic then you are reading, but your output is for the correct topic again. So the provided example is not consistent. |
Please use the high level consumer and check if this still happens. Also to be on the safe side, use a new consumer group |
@gordett @jfariablosis that's because you're using Think about it for a while. You're asking PHP to enter an infinite loop. You're never
|
good catch, thx @Steveb-p |
Hi @nick-zh and @Steveb-p, thanks a lot for your attention 1. Break when RD_KAFKA_RESP_ERR__PARTITION_EOF message is received or null (depends on configuration of librdkafka - don't worry about it now). 2. Disable output buffering, so that PHP actually writes to standard output (ob_flush). Otherwise whatever you echo is kept in buffer and doesn't reach webserver, which times out eventually. 3. Do not process messages using webserver (!). Usual use case for phprdkafka is for it to be a long running process in the background. While it will work for web requests, usually it's a bad idea. news... with high lever consumer i can see a lot of messages. but if i refresh i cant see nothing. i need to change de group.id to see again the messages. Sometimes not work..
now that i have some mensages, i have a big question... i can produce a message with laravel controller, when i make a request to some route
is it possible to do that? do you consider that i am following the right path? Thanks a lot |
A consumer (group) will ideally consume the message only once. After successful processing of one (or several messages) it is customary to commit the messages (or have auto commit enabled). Committed messages won't be re-read by the same consumer group. The message(s) are still available (if within retention limits) for other consumer groups to read. |
Yes, but if i produce more, i should see in consumer..
i dont understand, what i can do with consumer in php project.. because i dont want a page with a while (infinite loop) ... i want a page, that react a new message... and i only can do this with js file changing the dom od page Thanks a lot for everything |
|
Your client app will need to query the webserver for new messages, receive a response and then immediately query again. This technique is also known as Overall, familiarize yourself with consumer groups and others Kafka concepts. See if it will work for you. If you're building a messaging app, then Kafka is a bad choice - it just wasn't built for that. |
Hi @Steveb-p Thanks in advance |
@gordett If you're after messaging between users, then look into AMQP protocol first. See if it fits what you're trying to build before commiting to a solution. RabbitMQ is a popular implementation of a AMQP server, along with multitude of others. Just make sure you understand the limitation of each solution you look into. Don't get me wrong, Kafka is great for what it does, which makes it extremely performant, but it comes at a price. If in your app you need:
Then Kafka is not for your use case. |
@gordett @jfariablosis if you have any questions, you can also ask them on https://php-kafka.slack.com/ - this Slack isn't used too much, but Nick and I often sit there. |
Message app its only a example. I dont need search messages by date or phrase.. What i need is, some app flutter send a coordinates to a server (like api in laravel), and when this happens, i want to produce a message to my web page (html + js in laravel project) the client consume de message produced and update de map with data of the message or make a request ajax/axios to get last coordenates.... the kafka is to the client page dont need to make a lot requests (infinite loop like setTimeout) without coordenates updated... with kafka the client update only when news coordenates are inserted |
Then Kafka is a good choice. You just need to remember to set a proper timeout in Or use websockets, then you will have a permanent connection, and you'll be able to write to client directly. Familiarize yourself with those if you haven't already. |
Adjusted Slack link above so you guys can join. I'll close this ticket since the extension part has been resolved. Feel free to continue the discussion though ✌️ |
Bonjour
Nous sommes du Portugal.
Nous avons un probleme avec la configuration du kafka.
Le message cést:
Symfony\Component\Debug\Exception\FatalThrowableError
Class 'App\Http\Controllers\RdKafka\Conf' not found
Pouvez vous nous aider a resoudre ce problem?
Merci en avance
Joao Faria
The text was updated successfully, but these errors were encountered: