Inconsistant results from QueueBrowser.getEnumeration()
dsikkema Apr 8, 2010 10:24 PMI am porting a project from JBossMQ to HornetQ and have come across a stumbling block. One of the requirements is to be able to display all currently queued messages, both scheduled and in progress. I can do so with JBossMQ with code like:
List messages; messages = (List)server.invoke( new ObjectName( queueName ), "listInProcessMessages", new Object[] {}, new String[] {} ); process(messages); messages = (List)server.invoke( new ObjectName( queueName ), "listScheduledMessages", new Object[] {}, new String[] {} ); process(messages); messages = (List)server.invoke( new ObjectName( queueName ), "listMessages", new Object[] {}, new String[] {} ); process(messages);
With HornetQ I found that the listInProcessMessages and listMessages methods are not available, and the listMessages method requires a filter parameter, returns an array of maps, and for quite a while the array I got back was always empty. Once I did get data it turned out not to contain the object inside the message. After looking around it seemed to me the best solution would be to use QueueBrowser.getEnumeration(), but I found this too was always empty.
My testing involved an application running in JBoss AS4 with a single queue, and single listener, and queuing 19 ObjectMessages at a time (fairly small in size), each of which the listener takes between 5 and 60 seconds to process.
I was able to run the hornetQ browser example, so I slowly changed things in my code to exactly reproduce the example, and I finally received data from both the listMessages method and QueueBrowser.getEnumeration() when I removed the listener from my queue. Trying to understand why this allowed me to finally browse the data I guessed that all my messages were being buffered onto the listener as soon as they are sent and hence not available to be browsed. I added <consumer-window-size>0</consumer-window-size> to hornetq-jms.xml, but then QueueBrowser.getEnumeration() would only ever return 1 message, always the next scheduled message. When the current in progress message was completed and the currently browsable message was picked up by the listener I could then browse the next message until all were processed. I have since tried 1 and 1024 as for my consumer-window-size with very surprising results. I never get the same results from QueueBrowser.getEnumeration(). Always, I still get the next scheduled message, but sometime I get more messages, between 1 and 15 consecutive scheduled messages. While a single message is being processed I can run QueueBrowser.getEnumeration() several times. One time I get the next 3 scheduled messages. The next time I get the next 12 scheduled messages. The next time I get the next 1 scheduled message.
Does anyone know why I am getting these results?
Is there a configuration option I need to set or a different method I need to use to get this data? I will settle for only scheduled messages if in progress messages are not retrievable.
Any help you can give will be greatly appreciated.
Thanx