title: How can I get all messages from a ActiveMQ broker?
body: <p>So I have an ActiveMQ broker and some producers that puts some self made objects in the broker. I also have some consumers that receive those messages(serialized objects) without problem. But I want to create a tool that connects to the broker and displays all messages (serialized objects).</p>
  
  <p>I tried to do that using and ActiveMQConnection :</p>
  
  <pre><code>Set&lt;ActiveMQQueue&gt; currentMessageQueues = activeMQConnection.getDestinationSource().getQueues();
  Iterator&lt;ActiveMQQueue&gt; messageQueueIterator = currentMessageQueues.iterator();
  
  while (messageQueueIterator.hasNext()) {
      ActiveMQQueue currentQueue = messageQueueIterator.next();
      QueueSession queueSession = activeMQConnection.createQueueSession(true, Session.AUTO_ACKNOWLEDGE);
      QueueBrowser browser = queueSession.createBrowser(currentQueue);
      Enumeration&lt;?&gt; messagesInQueue = browser.getEnumeration();
  
      while (messagesInQueue.hasMoreElements()) {
         Message queueMessage = (Message) messagesInQueue.nextElement();
  
         if (queueMessage instanceof ActiveMQObjectMessage) {
            ActiveMQObjectMessage objectMessage = (ActiveMQObjectMessage) queueMessage;
            objectMessage.getObject();
         }
      }
   }
  </code></pre>
  
  <p>With this code I get an exception on objectMessage.getObject():</p>
  
  <pre><code>javax.jms.JMSException: Failed to build body from content. Serializable class not available to broker. Reason: java.lang.ClassNotFoundException: MyMessage
  </code></pre>
  
  <p>I used debug mode and ActiveMQObjectMessage has the object set to null.</p>
  
  <p>Is this approach good and If yes what I am doing wrong?
  How can I also receive the object from the broker?</p>