Author |
Message
|
jasmin |
Posted: Thu Dec 08, 2005 7:06 am Post subject: Problems with accessing the queue several times in a row |
|
|
Novice
Joined: 04 Nov 2005 Posts: 15
|
Hi.
I use the com.ibm.mq.jar library to access a message queue with my java application.
When I try to get a single message from the queue, my program works fine.
Code: |
int openOptionsGET = MQC.MQOO_INPUT_SHARED|MQC.MQOO_FAIL_IF_QUIESCING;
MQQueue MyQueue = qMgr.accessQueue(qQueue,openOptionsGET);
MQMessage MyMessage = new MQMessage();
MyQueue.get(MyMessage);
|
But as soon as I try to get more than one message in a loop, I receive a "Completion code 2 Reason code 2033" - error.
Example:
Code: |
int openOptions = MQC.MQOO_BROWSE | MQC.MQOO_INQUIRE;
MQQueue MyQueue_STATG = qMgr.accessQueue(qQueue, openOptions,null,null, null);
while (MyQueue_STATG.getCurrentDepth() > 0) {
MyQueue.get(MyMessage);
}
|
The error occurs though the condition in the while-statement is definetly true. (I've checked that.)
Does anybody know, what might went wrong?
Thanks. |
|
Back to top |
|
 |
jefflowrey |
Posted: Thu Dec 08, 2005 7:13 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
What went wrong is that you are trying to tell if the queue is empty by using the unreliable current queue depth message, instead of by whether or not you got a return code from the Get that was a 2033.
Also, it is fairly unlikely that you should be using MQC.MQOO_BROWSE.
Among other things, using BROWSE means that your queue depth won't go down when you GET a message. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
jasmin |
Posted: Thu Dec 08, 2005 7:22 am Post subject: |
|
|
Novice
Joined: 04 Nov 2005 Posts: 15
|
Actually the queue depth does go down with BROWSE, as it shows when you have a System.out.println() before and after the get.
Anyway, I've got know idea how else I could request all messages in a loop. Apart from that, I don't know exactely what messageid and corellid is?
Does anybody have sample code for such a case? |
|
Back to top |
|
 |
jasmin |
Posted: Thu Dec 08, 2005 7:27 am Post subject: |
|
|
Novice
Joined: 04 Nov 2005 Posts: 15
|
Besides, what exactely means error code 2033? |
|
Back to top |
|
 |
bower5932 |
Posted: Thu Dec 08, 2005 7:29 am Post subject: |
|
|
 Jedi Knight
Joined: 27 Aug 2001 Posts: 3023 Location: Dallas, TX, USA
|
You can use mqrc to get return code descriptions:
C:\Documents and Settings\Administrator>mqrc 2033
2033 0x000007f1 MQRC_NO_MSG_AVAILABLE
As far as sample code is concerned, there is some here and some more at:
http://www.developer.ibm.com/isv/tech/sampmq.html |
|
Back to top |
|
 |
jefflowrey |
Posted: Thu Dec 08, 2005 7:40 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
jasmin wrote: |
Actually the queue depth does go down with BROWSE, as it shows when you have a System.out.println() before and after the get. |
Ahh. That's because you opened the queue for BROWSING, but aren't specifying the BROWSE options on your get (MQGMO_BROWSE_FIRST or MQGMO_BROWSE_NEXT).
So you're not browsing, you're doing a destructive get.
Regardless, trying to use the queue depth is not the right way to find out when the queue is empty - for a lot of reasons. The right way is to keep getting messages until you get back MQRC_NO_MORE_MESSAGES... which is 2033! Or until you get some other exception/bad return code, that indicates something else is not right. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
jasmin |
Posted: Thu Dec 08, 2005 7:46 am Post subject: |
|
|
Novice
Joined: 04 Nov 2005 Posts: 15
|
Quote: |
Regardless, trying to use the queue depth is not the right way to find out when the queue is empty - for a lot of reasons. The right way is to keep getting messages until you get back MQRC_NO_MORE_MESSAGES... which is 2033! Or until you get some other exception/bad return code, that indicates something else is not right.
|
Why's that?
I found out the problem was, that I didn't close the queue before I started the next get. Now it works, with the BROWSE. Isn't this more consistent than waiting for an exception? |
|
Back to top |
|
 |
wschutz |
Posted: Thu Dec 08, 2005 8:32 am Post subject: |
|
|
 Jedi Knight
Joined: 02 Jun 2005 Posts: 3316 Location: IBM (retired)
|
Two reason why curdepth isn't reliable:
1. curdepth includes uncommitted messages that have been "put" but wouldn't be available to your application
2. if some other process is reading messages from the queue, they might have gotten the message between your inquiry for curdepth and your "get" of the message,
Also, I don't see how your code works since you didn't specify a MQOO_INPUT* option. _________________ -wayne |
|
Back to top |
|
 |
PeterPotkay |
Posted: Thu Dec 08, 2005 1:44 pm Post subject: |
|
|
 Poobah
Joined: 15 May 2001 Posts: 7722
|
wschutz wrote: |
Two reason why curdepth isn't reliable:
1. curdepth includes uncommitted messages that have been "put" but wouldn't be available to your application
2. if some other process is reading messages from the queue, they might have gotten the message between your inquiry for curdepth and your "get" of the message,
|
Reason #3, messages that are expired count towards q depth, but you can't get them. _________________ Peter Potkay
Keep Calm and MQ On |
|
Back to top |
|
 |
jasmin |
Posted: Thu Dec 08, 2005 11:36 pm Post subject: |
|
|
Novice
Joined: 04 Nov 2005 Posts: 15
|
Ok, you've convinced me. Could you post a sample code for doing it the other way? |
|
Back to top |
|
 |
wschutz |
Posted: Fri Dec 09, 2005 2:39 am Post subject: |
|
|
 Jedi Knight
Joined: 02 Jun 2005 Posts: 3316 Location: IBM (retired)
|
|
Back to top |
|
 |
|