Hi Shazni,

WSO2 Message Broker exposes Admin Services which you can get message count
of a queue.
Is there any chance of using that?

Thanks

On Fri, Sep 23, 2016 at 2:21 PM, Shazni Nazeer <sha...@wso2.com> wrote:

> 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>
>



-- 
*Hasitha Abeykoon*
Senior Software Engineer; WSO2, Inc.; http://wso2.com
*cell:* *+94 719363063*
*blog: **abeykoon.blogspot.com* <http://abeykoon.blogspot.com>
_______________________________________________
Dev mailing list
Dev@wso2.org
http://wso2.org/cgi-bin/mailman/listinfo/dev

Reply via email to