Author |
Message
|
platondaniel |
Posted: Mon Aug 26, 2002 3:10 am Post subject: getCurrentDepth() problem |
|
|
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 |
|
 |
dgolding |
Posted: Mon Aug 26, 2002 5:43 am Post subject: |
|
|
 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 |
|
 |
platondaniel |
Posted: Mon Aug 26, 2002 5:48 am Post subject: |
|
|
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 |
|
 |
dgolding |
Posted: Mon Aug 26, 2002 5:50 am Post subject: |
|
|
 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 |
|
 |
platondaniel |
Posted: Mon Aug 26, 2002 5:52 am Post subject: |
|
|
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 |
|
 |
platondaniel |
Posted: Mon Aug 26, 2002 5:56 am Post subject: |
|
|
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 |
|
 |
dgolding |
Posted: Mon Aug 26, 2002 6:09 am Post subject: |
|
|
 Yatiri
Joined: 16 May 2001 Posts: 668 Location: Switzerland
|
|
Back to top |
|
 |
nimconsult |
Posted: Thu Aug 29, 2002 11:37 pm Post subject: |
|
|
 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 |
|
 |
platondaniel |
Posted: Fri Aug 30, 2002 12:00 am Post subject: |
|
|
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 |
|
 |
nimconsult |
Posted: Fri Aug 30, 2002 12:24 am Post subject: |
|
|
 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 |
|
 |
|