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 » getCurrentDepth() problem

Post new topic  Reply to topic
 getCurrentDepth() problem « View previous topic :: View next topic » 
Author Message
platondaniel
PostPosted: Mon Aug 26, 2002 3:10 am    Post subject: getCurrentDepth() problem Reply with quote

Novice

Joined: 04 Aug 2002
Posts: 12

Hello !

I am trying to get all the messages in the queue at once. For that i use getCurrentDepth to determine if there are any messages in the queue.
Here's the code:

Code:
int depth = q.getCurrentDepth();
while ( depth > 0)
{
           q.get(message, gmo);
           msgText = message.readUTF();
           System.out.println("Msg: " + msgText);
           depth--;
}


And here's the output

Msg: Platon#Daniel
Unable to load message catalog - mqji
Exceptie aruncata de MQ. Completion code 2. Reason code 2033. Have a nice day !
com.ibm.mq.MQException: Completion Code 2, Reason 2033
at com/ibm/mq/MQQueue.get (MQQueue.java:493)
at GetMSGS.<init> (GetMSGS.java:35)
at GetMSGS.main (GetMSGS.java:57)

Same thing happens when I put
Code:
while (q.getQueueDepth() > 0)
{
    ...
}


What is the problem ? The getCurrentDepth() prints fine.

Thanks,
DAN
Back to top
View user's profile Send private message Yahoo Messenger
dgolding
PostPosted: Mon Aug 26, 2002 5:43 am    Post subject: Reply with quote

Yatiri

Joined: 16 May 2001
Posts: 668
Location: Switzerland

hi,

2033 is no message available, that satisfies your search criteria. First check you have intialised (set to zero) the MessId and CorrId fields.

Another possiblity is that the the message on the queue has expired. Well, it could happen, though not all the time - once maybe.

HTH

Don
Back to top
View user's profile Send private message Visit poster's website
platondaniel
PostPosted: Mon Aug 26, 2002 5:48 am    Post subject: Reply with quote

Novice

Joined: 04 Aug 2002
Posts: 12

Thaks for replying... but i don't use MessID and CorrID. Do I have to manually reset them after getting a message ?

There is no posibillity for message expiring. I've put it 2 minutes before running the Java program.

Thanks again,
DAN
Back to top
View user's profile Send private message Yahoo Messenger
dgolding
PostPosted: Mon Aug 26, 2002 5:50 am    Post subject: Reply with quote

Yatiri

Joined: 16 May 2001
Posts: 668
Location: Switzerland

It's good practise to implicitly set them to zero, prior to doing a GET. Otherwise, you could be looking for any old rubbish.

HTH
Back to top
View user's profile Send private message Visit poster's website
platondaniel
PostPosted: Mon Aug 26, 2002 5:52 am    Post subject: Reply with quote

Novice

Joined: 04 Aug 2002
Posts: 12

Ok. i set them to 0 (message.messageID = 0) but now it wouldn't compile. Says "Cannot convert int to byte[] "

DAN
Back to top
View user's profile Send private message Yahoo Messenger
platondaniel
PostPosted: Mon Aug 26, 2002 5:56 am    Post subject: Reply with quote

Novice

Joined: 04 Aug 2002
Posts: 12

Thanks a lot, it works... I should've write
Code:

message.messageId=MQC.MQMI_NONE ;
message.correlationId=MQC.MQMI_NONE;


Thanks,
DAN
Back to top
View user's profile Send private message Yahoo Messenger
dgolding
PostPosted: Mon Aug 26, 2002 6:09 am    Post subject: Reply with quote

Yatiri

Joined: 16 May 2001
Posts: 668
Location: Switzerland

Have fun!
Back to top
View user's profile Send private message Visit poster's website
nimconsult
PostPosted: Thu Aug 29, 2002 11:37 pm    Post subject: Reply with quote

Master

Joined: 22 May 2002
Posts: 268
Location: NIMCONSULT - Belgium

Hello Dan,

You should not use getCurrentDepth() as a programming practice to retrieve messages in a queue (even if your program works now).

Why?
- the queue depth can change after the call to getCurrentDepth and during the execution of your loop. The depth can either increase (new messages posted) or decrease (messages retrived by other applications/users).
- the queue depth includes expired messages, which you won't be able to retrieve.
- the queue depth includes uncommitted messages, which you won't be able to retrieve.

Instead, you should write the application so that the loop stops when MQGET returns a reason code 2033 (no message available).
_________________
Nicolas Maréchal
Senior Architect - Partner

NIMCONSULT Software Architecture Services (Belgium)
http://www.nimconsult.be
Back to top
View user's profile Send private message Send e-mail Visit poster's website
platondaniel
PostPosted: Fri Aug 30, 2002 12:00 am    Post subject: Reply with quote

Novice

Joined: 04 Aug 2002
Posts: 12

Hello !

Thx for the reply nimconsult. I've changed the code, it looks like this:

Code:
while (q.getCurrentDepth() > 0)
{
     .
     .
}


Isn't this testing every time if the queue has messages ? How exactly should I write this piece of code ?

The communication will be between an AS/400 server and a Windows NT Server, no users involved, only two apps which asincroneously operate on the queue putting and getting messages.

Besides, if 2033 is returned an exception is thrown...

Thx again,
DAN
Back to top
View user's profile Send private message Yahoo Messenger
nimconsult
PostPosted: Fri Aug 30, 2002 12:24 am    Post subject: Reply with quote

Master

Joined: 22 May 2002
Posts: 268
Location: NIMCONSULT - Belgium

You can write something like:

Code:

try
{
    while(true)
        {
            MQMessage msg = new MQMessage();
            q.get(msg);
            msgText = msg.readUTF();
            System.out.println("Msg: " + msgText);
        }
}
catch(MQException e)
{
    if (e.reasonCode != 2033)
        throw e;
}

_________________
Nicolas Maréchal
Senior Architect - Partner

NIMCONSULT Software Architecture Services (Belgium)
http://www.nimconsult.be
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » IBM MQ API Support » getCurrentDepth() problem
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.