Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP Stomp: Reading all messages in a queue
    text
    copied!<p>I need to find a specific message within an ActiveMQ queue using PHP and remove it. </p> <p>AFAIK the only way to do so is to read all messages that are currently queued and ACK the one message I'm interested in. (<a href="http://www.php.net/manual/en/stomp.ack.php" rel="nofollow">The example in the PHP manual for Stomp::ack</a> does more or less the same thing, they don't read all messages, but only ACK the one that matches).</p> <p>So, I wrote this code (this is only the relevant part, obviously):</p> <pre><code>class StompController { private $con; public function __construct($stompSettings) { try { $this-&gt;con = new Stomp($stompSettings['scheme']."://".$stompSettings['host'].":".$stompSettings['port']); $this-&gt;con-&gt;connect(); $this-&gt;con-&gt;setReadTimeout(5); } catch(StompException $e) { die('Connection failed:' .$e-&gt;getMessage()); } } public function __destruct() { $this-&gt;con-&gt;disconnect(); } public function ackMessageAsRead($recipient,$message) { if($this-&gt;con-&gt;isConnected()) { //Subscribe to the recipient user's message queue. $this-&gt;con-&gt;subscribe("/queue/".$recipient); //Read all messages currently in the queue (but only ACK the one we're interested in). while($this-&gt;con-&gt;hasFrameToRead()) { $msg = $this-&gt;con-&gt;readFrame(); if($msg != null &amp;&amp; $msg != false) { //This is the message we are currently reading, ACK it to AMQ and be done with it. if($msg-&gt;body == $message) { $this-&gt;con-&gt;ack($msg); } } } } else { return false; } } } </code></pre> <p>According to my logic, this should work. While running the code only <strong>one <em>random</em></strong> message is being read though, despite checking for more frames. </p> <p>The next frame seems only to be prepared when the frame we're currently reading has been ACK'ed. (When I manually ACK all messages the <code>while</code> loop works as intended, all messages are processed.</p> <p>Does anyone know how to get the full set of messages from the queue, without ACK'ing all of them? I can ACK all of them and put the ones I wasn't interested in back into the queue afterwards, but this already inefficient way to find a single message gets a whole lot more inefficient that way.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload