HI,

I have the following code snippet to calculate the number of message in the
JMS queue in Message Broker.

         ctx = new InitialContext(properties);
         QueueConnectionFactory connectionFactory =
(QueueConnectionFactory) ctx.lookup(CF_NAME);
         queueConnection = connectionFactory.createQueueConnection();

         queueSession = queueConnection.createQueueSession(false,
QueueSession.AUTO_ACKNOWLEDGE);
         Queue queue = (Queue) ctx.lookup(destinationName);

         QueueBrowser queueBrowser = queueSession.createBrowser(queue);

         queueConnection.start();

         Enumeration e = queueBrowser.getEnumeration();
         int numMsgs = 0;

         while (e.hasMoreElements()) {
             Message message = (Message) e.nextElement();
             numMsgs++;
         }


When the statement e.nextElement(); is executed it throws an exception. The
error message I could see in the debug session when executing this line is
"java.lang.ClassCastException:
org.wso2.andes.client.message.CloseConsumerMessage cannot be cast to
org.wso2.andes.client.message.AbstractJMSMessage"

What's wrong with this snippet? Why is it retrieving CloseConsumerMessage?

Is there any better way to determine the number of messages in the queue
programmatically?

Shazni Nazeer
Associate Technical Lead | WSO2

Mob : +94 777737331
LinkedIn : http://lk.linkedin.com/in/shazninazeer
Blog : http://shazninazeer.blogspot.com

<http://wso2.com/signature>
_______________________________________________
Dev mailing list
Dev@wso2.org
http://wso2.org/cgi-bin/mailman/listinfo/dev

Reply via email to