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