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 8932727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:22:37+00:00 2026-06-15T09:22:37+00:00

I am using Active MQ and the Java JMS. I want to count the

  • 0

I am using Active MQ and the Java JMS.

I want to count the number of messages on the queue.

One approach is counting the messeages with a browser:

    Queue queue = (Queue) session.createQueue(subject);
    QueueBrowser queueBrowser = session.createBrowser(queue);
    Enumeration<?> e = queueBrowser.getEnumeration();
    int numMsgs = 0;
    // count number of messages
    while (e.hasMoreElements()) {
    //    Message m = (Message) e.nextElement();
        e.nextElement();
        numMsgs++;
    }

But for a queue with 5000 pending requests, this only return 500.

Another approach is this (iterate all the messeages in the queue):

Message message= consumer.receive(500);
while(message!= null)
    {

        if (message instanceof TextMessage) 
        {
            TextMessage textMessage = (TextMessage) message;
       //     BytesMessage Byte

            System.out.println("Received message '"+ textMessage.getText() + "'");
        }
        if(message!=null)
            Messages_list.add(message);

        message = consumer.receive(1);
    } 

But this also dont give the right amount of messages pending.

How can i confidently iterate akk the messages waiting in the queue?

  • 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-15T09:22:38+00:00Added an answer on June 15, 2026 at 9:22 am

    There is a bug in ActiveMQ that is preventing the browse from returning the actual number of messages. In this case the browse is only returning a single page of messages, which is set by the maxPageSize property and documented here: http://activemq.apache.org/per-destination-policies.html

    ActiveMQ currently has a bug report on this issue and it is being tracked here: https://issues.apache.org/jira/browse/AMQ-4181. This issue has been resolved and is currently scheduled to be fixed in ActiveMQ 5.8.0.

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

Sidebar

Related Questions

How to get the browser window or active tab url using java script in
I am writing some Java code that authenticates to Active Directory using SASL GSSAPI.
I trying to implement the active record pattern using Java/JDBC and MySQL along with
I am using Active Record on CodeIgniter. I am confused on which approach I
I'm trying to lookup a user on a local active-directory using java. When I
I'd like to send a search string to Microsoft's Active Directory (using Java) that
We logon users to Active Directory via LDAP using the Java LDAP API. We
Is it possible to open pop-up windows BEHIND the current active screen using java
I want to constantly monitor whether a site is active or not using the
Possible Duplicate: how to read a xml file using java? I want to the

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.