Author |
Message
|
sumit.wadhwa21 |
Posted: Mon Oct 23, 2006 10:09 pm Post subject: how to know the number of messages in a queue |
|
|
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 |
|
 |
Mr Butcher |
Posted: Mon Oct 23, 2006 11:42 pm Post subject: |
|
|
 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 |
|
 |
fjb_saper |
Posted: Tue Oct 24, 2006 2:34 am Post subject: |
|
|
 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 |
|
 |
hoa_lan_trang1982 |
Posted: Tue Nov 21, 2006 6:26 pm Post subject: |
|
|
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 |
|
 |
RogerLacroix |
Posted: Tue Nov 21, 2006 9:54 pm Post subject: |
|
|
 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 |
|
 |
Nigelg |
Posted: Tue Nov 21, 2006 11:48 pm Post subject: |
|
|
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 |
|
 |
Bartez75 |
Posted: Mon Jan 15, 2007 9:09 am Post subject: |
|
|
 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 |
|
 |
pathipati |
Posted: Mon Jan 15, 2007 9:15 am Post subject: |
|
|
Master
Joined: 03 Mar 2006 Posts: 296
|
What will you do if you know the queue depth? |
|
Back to top |
|
 |
KevinF23492 |
Posted: Mon Jan 15, 2007 11:44 am Post subject: |
|
|
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 |
|
 |
Bartez75 |
Posted: Tue Jan 16, 2007 1:33 am Post subject: |
|
|
 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 |
|
 |
zpat |
Posted: Tue Jan 16, 2007 1:39 am Post subject: |
|
|
 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 |
|
 |
|