Answer the question
In order to leave comments, you need to log in
ReactPHP + RabbitMQ how to do a non-blocking wait for a new message?
Good day to all.
Actually a question. I decided to make posts on the site on ReactPHP + RabbitMQ hoping for asynchrony in long pooling. But in fact, PhpAmqpLib uses a blocking wait. Can someone tell me how to wait and not be blocked?
Answer the question
In order to leave comments, you need to log in
I didn’t quite understand about PhpAmqpLib blocking waits, in the amqp extension for php there is quite a non blocking get method. It seems to me that phpdaemon is
suitable for your task . Of course, you will also have to use timers (asynchronous timers are implemented in phpdaemon via libevent), or wait until the amqp protocol is implemented for it . Plus, everything is perfectly parallel due to the asynchronous operation of the framework.
What do you mean by non-blocking wait? If you connected - checked messages - disconnected - then this suggests that such an operation needs to be performed with a certain frequency, then the meaning of RabbitMQ in this scenario is lost, because it is possible to check new messages at once in a DBMS after a certain interval of time for example.
As for messages and RabbitMQ, you can create 2 queues, (one for sending messages, the other for receiving). Accordingly, to receive messages, we connect to the queue, listen to messages from it and, upon receipt, issue it to the user. To send messages, we send a separate request in the second queue, there will be no blocking here.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question