Question

I am currently using stomp to send and receive/consume messages in activemq queues, but the stomp consumer is working synchronously , meaning the stomp consumer keeps checking if there is any new messages in the queue .But what I need to do is to make activemq notify my stomp consumer when a new message enters the queue . like the Onmessage() method in Java for example . I searched for days but still no luck . my current php code ( how I read messages from queue using stomp) :

while (true) {

       $frame = $stomp->readFrame();
       if ($frame != NULL) {
           print "Received: " . $frame->body . " - time now is " . date("Y-m-d H:i:s"). "\n";
           $stomp->ack($frame);
       }
       else {
       print "No frames to read\n";
   }
Était-ce utile?

La solution

solved the problem .

used github.com/reactphp/stomp library and it worked perfectly . it consumes messages from my message broker asynchronously now .

Autres conseils

I've checked reactphp/stomp library and looks great. I think that the messages are read either way, but I like the event-driven sense that the scheduled timer adds to the application design. In my opinion, just go with it. For all other people not interested in using yet another new library but still worried about the overhead of an infinite loop checking every CPU tick, here are 2 options to explore: - Adding a sleep($timeout) before next check (end of each iteration) - Using the Event class distributed as PECL extension (not bundled with PHP)

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top