Vote count:
0
I'm fiddling around with a JMS Queue using ActiveMQ and I wanted to work out a Queue Browser. I've looked up some examples on the web but I'm having quite a bit of trouble getting it to work.
Here is the relevant code:
QueueBrowser browser = template.execute(new SessionCallback<QueueBrowser>() {
public QueueBrowser doInJms(Session session) throws JMSException {
return session.createBrowser(queue);
}
}, true);
Enumeration messages = browser.getEnumeration();
int num = 0;
while(messages.hasMoreElements()) {
messages.nextElement();
num +=1;
}
logger.info("Num = " + num);
I've injected in the template and queue, and using some log statements I have verified that they are the objects I want. I can even retrieve the queue from the QueueBrowser once it is instantiated. I've populated the queue with about 100 messages and am reading them off using a custom JmsMessageListener that has about a 1 sec delay between reads.
However, the issue is that the code hangs around the while(messages.hasMoreElements() line. From debugging, it never even goes inside the loop. If I have that line of code in a logger to check the value the hanging also occurs.
If I merely use the enumeration to nextElement() without looping, then I'm returned a null value. I cannot determine whether this means the queue or enumeration is empty. If so, shouldn't messages hasMoreElements() return a proper boolean value?
Could the issue be that I'm reading messages with a JmsMessageListener? Am I using the template wrong? I can't really determine where something is going wrong because it appears that 90% of it is working, its just the last 10% that seems to be acting oddly.
JMS QueueBrowser hanging on getEnumeration()
Aucun commentaire:
Enregistrer un commentaire