Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8600317
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:35:24+00:00 2026-06-12T01:35:24+00:00

I need to find a specific message within an ActiveMQ queue using PHP and

  • 0

I need to find a specific message within an ActiveMQ queue using PHP and remove it.

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. (The example in the PHP manual for Stomp::ack does more or less the same thing, they don’t read all messages, but only ACK the one that matches).

So, I wrote this code (this is only the relevant part, obviously):

class StompController {

    private $con;

    public function __construct($stompSettings) {
        try {
            $this->con = new Stomp($stompSettings['scheme']."://".$stompSettings['host'].":".$stompSettings['port']);
            $this->con->connect();
            $this->con->setReadTimeout(5);
        } catch(StompException $e) {
            die('Connection failed:' .$e->getMessage());
        }
    }

    public function __destruct() {
        $this->con->disconnect();
    }

    public function ackMessageAsRead($recipient,$message) {
        if($this->con->isConnected()) {
            //Subscribe to the recipient user's message queue.
            $this->con->subscribe("/queue/".$recipient);
            //Read all messages currently in the queue (but only ACK the one we're interested in).
            while($this->con->hasFrameToRead()) {
                $msg = $this->con->readFrame();
                if($msg != null && $msg != false) {
                    //This is the message we are currently reading, ACK it to AMQ and be done with it.
                    if($msg->body == $message) {
                        $this->con->ack($msg);
                    }
                } 
            }
        } else {
            return false;
        }
    }
}

According to my logic, this should work.
While running the code only one random message is being read though, despite checking for more frames.

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 while loop works as intended, all messages are processed.

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T01:35:25+00:00Added an answer on June 12, 2026 at 1:35 am

    I think this is an issue due to setting activemq.prefetchSize to 1. ActiveMQ uses a prefetch size on how many messages can be dispatched to a consumer at any point in time. Once the prefetch size is reached, no more messages are dispatched to the consumer until the consumer starts sending back acknowledgements. Increasing the prefetch size should fix your issue to my best knowledge.

    Please read http://activemq.apache.org/what-is-the-prefetch-limit-for.html for more details on prefetch limit.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to find using PL/SQL if a specific sequence named e.g. MY_SEQ exits.
i have a big solution containing that much projects..i need to find a specific
I need to find the columns in a specific table, which is no problem:
I need to index specific strings with other strings and I can't really find
I need to find a flexible solution for access control in PHP. In the
I need to find all the occurences of a file Test.TXT in c:\ or
I need to find in a specific folder if there exist a file with
I need to find the specific time a tap happens and then the time
Need to find the timestamp for the first minute of the first day of
i need to find out automationid for key board values? how to send keystrokes

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.