Note that there are some explanatory texts on larger screens.

plurals
  1. POActiveMQ get all messages from the queue
    primarykey
    data
    text
    <p>I want to create some tool which will be able to manage messages inside queue. So I would like to be able to get all the messages from the queue(something like export) and don't remove it from there. </p> <p>I tried to use JMX API: </p> <pre><code> ObjectName mbeanNameQueue = new ObjectName("org.apache.activemq:type=Broker,brokerName=static-broker1,destinationType=Queue,destinationName=tmp_queue2"); org.apache.activemq.broker.jmx.QueueViewMBean queueView = JMX.newMBeanProxy(mbsc, mbeanNameQueue, org.apache.activemq.broker.jmx.QueueViewMBean.class); System.out.println(queueView.browseAsTable()); </code></pre> <p>But I can not get more than 400 messages.</p> <p>Also I used such approach:</p> <pre><code> ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://localhost:55901"); ActiveMQConnection connection = (ActiveMQConnection)connectionFactory.createConnection(); DestinationSource ds = connection.getDestinationSource(); QueueSession queueSession = connection.createQueueSession(true, Session.CLIENT_ACKNOWLEDGE); Queue queue = queueSession.createQueue("tmp_queue2"); QueueBrowser browser = queueSession.createBrowser(queue); Enumeration&lt;?&gt; messagesInQueue = browser.getEnumeration(); while (messagesInQueue.hasMoreElements()) { Message queueMessage = (Message) messagesInQueue.nextElement(); System.out.println(queueMessage); } </code></pre> <p>but messagesInQueue.hasMoreElements() always returns false despite the queue contains many messages.</p> <p>Also if I try to use consumer it retrieves all the messages but it removes it from the queue.</p> <p>I tried to export messages from the queue using command line tool:</p> <pre><code>activemq browse --amqurl tcp://localhost:55901 tmp_queue2 &gt;&gt; messages22222.txt </code></pre> <p>But if queue contains about 1000000 messages it throws </p> <pre><code>Failed to execute main task. Reason: java.lang.OutOfMemoryError: GC overhead limit exceeded </code></pre> <p>So, how can I get all the messages form the queue and don't remove them from there?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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