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 Java / JMS » Problems with accessing the queue several times in a row

Post new topic  Reply to topic
 Problems with accessing the queue several times in a row « View previous topic :: View next topic » 
Author Message
jasmin
PostPosted: Thu Dec 08, 2005 7:06 am    Post subject: Problems with accessing the queue several times in a row Reply with quote

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
View user's profile Send private message
jefflowrey
PostPosted: Thu Dec 08, 2005 7:13 am    Post subject: Reply with quote

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
View user's profile Send private message
jasmin
PostPosted: Thu Dec 08, 2005 7:22 am    Post subject: Reply with quote

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
View user's profile Send private message
jasmin
PostPosted: Thu Dec 08, 2005 7:27 am    Post subject: Reply with quote

Novice

Joined: 04 Nov 2005
Posts: 15

Besides, what exactely means error code 2033?
Back to top
View user's profile Send private message
bower5932
PostPosted: Thu Dec 08, 2005 7:29 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger
jefflowrey
PostPosted: Thu Dec 08, 2005 7:40 am    Post subject: Reply with quote

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
View user's profile Send private message
jasmin
PostPosted: Thu Dec 08, 2005 7:46 am    Post subject: Reply with quote

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
View user's profile Send private message
wschutz
PostPosted: Thu Dec 08, 2005 8:32 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail AIM Address
PeterPotkay
PostPosted: Thu Dec 08, 2005 1:44 pm    Post subject: Reply with quote

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
View user's profile Send private message
jasmin
PostPosted: Thu Dec 08, 2005 11:36 pm    Post subject: Reply with quote

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
View user's profile Send private message
wschutz
PostPosted: Fri Dec 09, 2005 2:39 am    Post subject: Reply with quote

Jedi Knight

Joined: 02 Jun 2005
Posts: 3316
Location: IBM (retired)

see mqbrowse.java, here:
http://www.developer.ibm.com/isv/tech/sampmq.html
_________________
-wayne
Back to top
View user's profile Send private message Send e-mail AIM Address
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » IBM MQ Java / JMS » Problems with accessing the queue several times in a row
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.