|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
Can you use a GET command in a loop ? |
« View previous topic :: View next topic » |
Author |
Message
|
AlexeiSkate |
Posted: Thu Apr 18, 2002 12:31 pm Post subject: |
|
|
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 |
|
 |
StefanSievert |
Posted: Thu Apr 18, 2002 12:43 pm Post subject: |
|
|
 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 |
|
 |
AlexeiSkate |
Posted: Thu Apr 18, 2002 1:08 pm Post subject: |
|
|
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 |
|
 |
StefanSievert |
Posted: Thu Apr 18, 2002 1:51 pm Post subject: |
|
|
 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 |
|
 |
AlexeiSkate |
Posted: Fri Apr 19, 2002 6:29 am Post subject: |
|
|
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 |
|
 |
|
|
 |
|
Page 1 of 1 |
|
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
|
|
|
|