Author |
Message
|
Zoli |
Posted: Sun Dec 03, 2006 10:51 am Post subject: Check if queue is empty |
|
|
Newbie
Joined: 03 Dec 2006 Posts: 3
|
Hi,
I am a newbie and trying to check if the queue is empty (0 message) before attempting to get a message. It seems a basic task but I cannot find any solution to it.
Any idea is appreciated.
Thanks. |
|
Back to top |
|
 |
fjb_saper |
Posted: Sun Dec 03, 2006 1:46 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
Quite easy: in base do a get if it returns with reason code 2033 the queue is empty (no message in a getable state)
In JMS do a receive. If the message is null same story...
If you want the check to be non destructive do a browse. If the browse does not allow you to see any message your queue is empty(no message in a getable/browseable state).
Enjoy  _________________ MQ & Broker admin |
|
Back to top |
|
 |
Zoli |
Posted: Sun Dec 03, 2006 11:53 pm Post subject: |
|
|
Newbie
Joined: 03 Dec 2006 Posts: 3
|
I managed to do it by checking if the reason code is 2033, but as you say, I would like to make it in a non-destructive way. How would you check the browseable state in C# (if there is a means to do it)?
Thanks for your help. |
|
Back to top |
|
 |
jefflowrey |
Posted: Mon Dec 04, 2006 3:00 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
Don't bother.
Read the first message, destructively. If you get a 2033, then there's nothing more to do for now. If you don't get a 2033, then process the message.
Why do you want to know if you need to get a message before you try to get a message? _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
bruce2359 |
Posted: Tue Dec 05, 2006 7:18 am Post subject: |
|
|
Guest
|
It is a rare application that would need to know the current depth of a queue without the intent to MQGET the messages.
However, here is how you check to see if there are messages in a queue, but not (attempt to) MQGET them:
1. MQOPEN the queue for inquire; then
2. MQINQuire on current depth; then
3. MQCLOSE the queue.
This is not a best practice for all applications, since you have added three MQI calls. As prior posts suggest, your applications attempt to MQGET a message with either get a message or return a 2033 reason code. |
|
Back to top |
|
 |
kevinf2349 |
Posted: Tue Dec 05, 2006 7:27 am Post subject: |
|
|
 Grand Master
Joined: 28 Feb 2003 Posts: 1311 Location: USA
|
Quote: |
This is not a best practice for all applications, since you have added three MQI calls. |
...and the value for depth may well be inaccurate (expired messages etc). |
|
Back to top |
|
 |
Zoli |
Posted: Tue Dec 05, 2006 1:12 pm Post subject: |
|
|
Newbie
Joined: 03 Dec 2006 Posts: 3
|
It seems, I just have to stick to checking the 2033 reason code - simple and works fine...
Thanks all of you for the suggestions. |
|
Back to top |
|
 |
mvarghese |
Posted: Fri Dec 08, 2006 12:10 am Post subject: can i check Qdepth from Message Broker |
|
|
Centurion
Joined: 27 Sep 2006 Posts: 141
|
Is it possible to check Qdepth from message broker using ESQL?.so that i can route the message to different destination.
What i know, its not possible ?if yes, please explain how? _________________ Jain Varghese |
|
Back to top |
|
 |
Vitor |
Posted: Fri Dec 08, 2006 12:20 am Post subject: Re: can i check Qdepth from Message Broker |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
mvarghese wrote: |
Is it possible to check Qdepth from message broker using ESQL?.so that i can route the message to different destination.
What i know, its not possible ?if yes, please explain how? |
Can you give us a bit more detail on the requirement? I'm not immediately clear on how qdepth would affect message routing - normally it's content.  _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
wschutz |
Posted: Fri Dec 08, 2006 5:38 am Post subject: Re: can i check Qdepth from Message Broker |
|
|
 Jedi Knight
Joined: 02 Jun 2005 Posts: 3316 Location: IBM (retired)
|
Vitor wrote: |
mvarghese wrote: |
Is it possible to check Qdepth from message broker using ESQL?.so that i can route the message to different destination.
What i know, its not possible ?if yes, please explain how? |
Can you give us a bit more detail on the requirement? I'm not immediately clear on how qdepth would affect message routing - normally it's content.  |
I've seen more "interesting" ideas reading mqseries.net than I ever thought possible ...
anyways, if thats what you really want to do (and I agree with Vitor that its an unusual requirement), I had a long conversation with someone maybe 1 to 1-1/2 years ago here on writing and reading PCF messages from ESQL...if you search hard enough you'll find it ... good luck!  _________________ -wayne |
|
Back to top |
|
 |
jefflowrey |
Posted: Fri Dec 08, 2006 5:45 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
|
Back to top |
|
 |
wschutz |
Posted: Fri Dec 08, 2006 5:48 am Post subject: |
|
|
 Jedi Knight
Joined: 02 Jun 2005 Posts: 3316 Location: IBM (retired)
|
not that hard for a "Grand Poobah"...  _________________ -wayne |
|
Back to top |
|
 |
Vitor |
Posted: Fri Dec 08, 2006 5:52 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
wschutz wrote: |
not that hard for a "Grand Poobah"...  |
Nothing is hard for the Grand Poobah!!
Still trying to get my head round routing by queue depth though...  _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
kevinf2349 |
Posted: Fri Dec 08, 2006 6:07 am Post subject: |
|
|
 Grand Master
Joined: 28 Feb 2003 Posts: 1311 Location: USA
|
Quote: |
Still trying to get my head round routing by queue depth though... |
Maybe it is for workload management/balancing?  |
|
Back to top |
|
 |
wschutz |
Posted: Fri Dec 08, 2006 6:08 am Post subject: |
|
|
 Jedi Knight
Joined: 02 Jun 2005 Posts: 3316 Location: IBM (retired)
|
Vitor wrote: |
Still trying to get my head round routing by queue depth though...  |
Easy... if there are no messages, then don't route...if there are messages, then route them (sorry, maybe its the water here) _________________ -wayne |
|
Back to top |
|
 |
|