ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » IBM MQ API Support » how to know the number of messages in a queue

Post new topic  Reply to topic
 how to know the number of messages in a queue « View previous topic :: View next topic » 
Author Message
sumit.wadhwa21
PostPosted: Mon Oct 23, 2006 10:09 pm    Post subject: how to know the number of messages in a queue Reply with quote

Newbie

Joined: 10 Oct 2006
Posts: 7

I am using browse option to read the message fromthe queue, but when all the messages are read from the queue, it doesn't throw exception. It gets struck in a loop and never ends. Can i get the number of message sin a queue so that i will make my loop run onlt that much number of time which equals number of messages in queue.
Code is attached:
mqGetMsgOpts = new MQGetMessageOptions();

mqGetMsgOpts.Options = MQC.MQGMO_BROWSE_FIRST | MQC.MQGMO_WAIT;

//MQC.MQOO_INPUT_AS_Q_DEF + MQC.MQOO_FAIL_IF_QUIESCING;

mqGetMsgOpts.WaitInterval = MQC.MQWI_UNLIMITED;

bool isContinue = true;
while (isContinue)
{
MQMessage mqMsg; // MQMessage instance
mqMsg = new MQMessage();

try
{
mqQueue1.Get(mqMsg, mqGetMsgOpts);
//mqGetMsgOpts.Options = MQC.MQGMO_BROWSE_NEXT ;

String msgText = mqMsg.ReadString(mqMsg.MessageLength);



// Response.Write(mqMsg.ReadString(mqMsg.MessageLength));

mqMsg.ClearMessage();
// mqQueue1.Close();
mqGetMsgOpts.Options = MQC.MQGMO_BROWSE_NEXT | MQC.MQGMO_WAIT;
// iQLevel--;

}
catch (MQException mqe)
{
if (mqe.Reason == MQC.MQRC_NO_MSG_AVAILABLE)
{
// special report for normal end
Response.Write("no more messages");
isContinue = false;
}
else
{
// general report for other reasons
Response.Write("MQQueue::Get ended with " + mqe.Message);

// treat truncated message as a failure for this sample
if (mqe.Reason == MQC.MQRC_TRUNCATED_MSG_FAILED)
{
isContinue = false;
}
}
}
Back to top
View user's profile Send private message
Mr Butcher
PostPosted: Mon Oct 23, 2006 11:42 pm    Post subject: Reply with quote

Padawan

Joined: 23 May 2005
Posts: 1716

maybe you should re-read about this option that you are using:

MQC.MQGMO_WAIT
_________________
Regards, Butcher
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Tue Oct 24, 2006 2:34 am    Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20756
Location: LI,NY

Any way counting the messages in a queue in order to know the # of loops is always a BAD IDEA. Check out there's been a number of posts about this already. Long story short: look up reason code 2033.

Enjoy
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
hoa_lan_trang1982
PostPosted: Tue Nov 21, 2006 6:26 pm    Post subject: Reply with quote

Newbie

Joined: 15 Nov 2006
Posts: 7

Quote:
Any way counting the messages in a queue in order to know the # of loops is always a BAD IDEA. Check out there's been a number of posts about this already. Long story short: look up reason code 2033.

Enjoy

I don't know exactly what you mean. Can you tell me know more?[/quote]
Back to top
View user's profile Send private message
RogerLacroix
PostPosted: Tue Nov 21, 2006 9:54 pm    Post subject: Reply with quote

Jedi Knight

Joined: 15 May 2001
Posts: 3264
Location: London, ON Canada

hoa_lan_trang1982 wrote:
Quote:
Any way counting the messages in a queue in order to know the # of loops is always a BAD IDEA. Check out there's been a number of posts about this already. Long story short: look up reason code 2033.

Enjoy

I don't know exactly what you mean. Can you tell me know more?

He's trying to tell you that you are coding your application the wrong way - you simply loop until the application receives a 2033 reason code. Please read the WMQ Application Programming Guide for more information.

Regards,
Roger Lacroix
Capitalware Inc.
_________________
Capitalware: Transforming tomorrow into today.
Connected to MQ!
Twitter
Back to top
View user's profile Send private message Visit poster's website
Nigelg
PostPosted: Tue Nov 21, 2006 11:48 pm    Post subject: Reply with quote

Grand Master

Joined: 02 Aug 2004
Posts: 1046

Using unlimited wait will never return unless a msg arrives on the queue. You need to set a WaitInterval to get a 2033.
_________________
MQSeries.net helps those who help themselves..
Back to top
View user's profile Send private message
Bartez75
PostPosted: Mon Jan 15, 2007 9:09 am    Post subject: Reply with quote

Voyager

Joined: 26 Oct 2006
Posts: 80
Location: Poland, Wroclaw

Is there any other way to check the depth of the queue? Browse will take time.
Back to top
View user's profile Send private message
pathipati
PostPosted: Mon Jan 15, 2007 9:15 am    Post subject: Reply with quote

Master

Joined: 03 Mar 2006
Posts: 296

What will you do if you know the queue depth?
Back to top
View user's profile Send private message Yahoo Messenger
KevinF23492
PostPosted: Mon Jan 15, 2007 11:44 am    Post subject: Reply with quote

Novice

Joined: 26 Dec 2006
Posts: 22

Bartez75 wrote:
Is there any other way to check the depth of the queue? Browse will take time.


yes...PCF messages. But the question still remains....why do you need to know?

If you are trying to determine the depth in order to work out how many times to loop then, as others have already said...bad idea.

If you just want to know the number of messages for monitoring, fair enough, but then there are plenty of ways to do this for free and you need to truly understand how the depth shown may not reflect the true depth of the queue.
Back to top
View user's profile Send private message
Bartez75
PostPosted: Tue Jan 16, 2007 1:33 am    Post subject: Reply with quote

Voyager

Joined: 26 Oct 2006
Posts: 80
Location: Poland, Wroclaw

Ok. I understand it now. I wanted to have it for loop but as KevinF23492 said the depth of the queue can be changed before I go to end of all messages. It is better to loop untill application recives reason code 2033.

thanks.
Back to top
View user's profile Send private message
zpat
PostPosted: Tue Jan 16, 2007 1:39 am    Post subject: Reply with quote

Jedi Council

Joined: 19 May 2001
Posts: 5866
Location: UK

Use the MQI call MQINQ, not PCF in an application!

But there is normally no need for this.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » IBM MQ API Support » how to know the number of messages in a queue
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.