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 » Can you use a GET command in a loop ?

Post new topic  Reply to topic
 Can you use a GET command in a loop ? « View previous topic :: View next topic » 
Author Message
AlexeiSkate
PostPosted: Thu Apr 18, 2002 12:31 pm    Post subject: Reply with quote

Centurion

Joined: 10 Apr 2002
Posts: 123

Hi,

Is there a way to get all of the messages off the queue by using a 'while loop' or a 'for loop' ? What would the test condition be to terminate the loop, e.g. while (queue has more messages) ... ?


thanks,
Alex
Back to top
View user's profile Send private message
StefanSievert
PostPosted: Thu Apr 18, 2002 12:43 pm    Post subject: Reply with quote

Partisan

Joined: 28 Oct 2001
Posts: 333
Location: San Francisco

Alex,
of course this is possible, that's the recommended way of processing: drain the queue until empty.
Your loop condition could be as simple as:
while( CompCode != MQCC_FAILED )
But it depends on what non MQCC_OK conditions you might treat as OK, for example it might be tolerable to continue processing on certain MQCC_WARNING conditions. It depends on what your business logic is.
Remember to test for reason code MQRC_NO_MSG_AVAILABLE (2033) before you report an error condition, because this reason code will be reported as MQCC_FAILED.
One other thing to make sure, when you drain the queue: Reset your messageID/correlID to MQMI_NONE/MQCI_NONE before each MQGET.
The sample program amqsget0.c may help you to get started, along with the Application Programming Guide and Reference.
Cheers,
Stefan

_________________
Stefan Sievert
IBM Certified * MQSeries

In the end everything is right. If not, it's not the end.

[ This Message was edited by: StefanSievert on 2002-04-18 13:44 ]
Back to top
View user's profile Send private message
AlexeiSkate
PostPosted: Thu Apr 18, 2002 1:08 pm    Post subject: Reply with quote

Centurion

Joined: 10 Apr 2002
Posts: 123

Stephan,

I see that you can reference the CompCode directly when using MQI and code statement like "if (CompCode == MQCC_FAILED)", but how can you do similar logic when using the MQSeries for Java ? In Java, the completion code is an attribute of the MQException object. If I try to do a GET and there is no more message to be read, an exception is thrown to the catch block of the program and any remaining logic within the try-catch block is not executed. Do you have any idea on how I duplicate the MQI logic when using the Java API ?

thanks,
Alex
Back to top
View user's profile Send private message
StefanSievert
PostPosted: Thu Apr 18, 2002 1:51 pm    Post subject: Reply with quote

Partisan

Joined: 28 Oct 2001
Posts: 333
Location: San Francisco

Alex,
you didn't mention that you were referring to Java.
In that case your logic probably looks like
Quote:

try
{
while(true)
{
reset messageID/CorrelID (or create new MQMessage object)
get
do your OK processing
}
}
catch( MQException mqe )
{
if( mqe.Reason == MQC.MQRC_NO_MSG_AVAILABLE )
{
probably OK, do nothing
}
else
{
probably not OK, do your error processing
}
}
catch( other exceptions )
{
...
}

I am not a Java expert so the code above might be totally wack-o, plus I did it from the top of my head.
Yes, you will leave your try block when an exception occurs, but isn't that what you want anyway?
Maybe I don't really understand your question, so please correct me if you meant something different.
Stefan

_________________
Stefan Sievert
IBM Certified * MQSeries

In the end everything is right. If not, it's not the end.

[ This Message was edited by: StefanSievert on 2002-04-18 14:52 ]
Back to top
View user's profile Send private message
AlexeiSkate
PostPosted: Fri Apr 19, 2002 6:29 am    Post subject: Reply with quote

Centurion

Joined: 10 Apr 2002
Posts: 123

Stephan,

Thanks for your help. I guess I just have always look at the catch block as a place to catch and issue error and that any actual programming logic takes place only with the try block. But now if I need to do some other processing logic in my program after retrieving all of the msgs off the queue, I will do that in the catch block. Thanks again for your help.


Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » IBM MQ Java / JMS » Can you use a GET command in a loop ?
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.