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 » Newbie problem browsing a queue

Post new topic  Reply to topic
 Newbie problem browsing a queue « View previous topic :: View next topic » 
Author Message
Björn
PostPosted: Wed Sep 10, 2003 4:15 am    Post subject: Newbie problem browsing a queue Reply with quote

Newbie

Joined: 10 Sep 2003
Posts: 7

Hello everyone!

I'm a real beginner when it comes to MQSeries. My task is to write a Java program, that would connect to an MQSeries-Server, access and get all messages from a queue, then connect to another Queuemanager, access another Queue and post a series of messages there.

The server is all set up for this and all I care about is my little client application. While browsing the IBM-Site I found this mqbrowse.java sample program which helped me a great deal by showing me how to browse a MessageQueue. However, what it doesnt show me is how to browse all messages in a queue without causing an exception. So my question is, how to end my loop with the last message?
In my little program I'm always getting this error:

MQJE001: Beendigungscode 2, Ursache 2033

Of course I know that it runs into an exception as my loop doesnt stop with the last message.

This is the loop I'm using to browse the queue:

Code:
MQGetMessageOptions gmo = new MQGetMessageOptions();
         gmo.options          = MQC.MQGMO_WAIT | MQC.MQGMO_BROWSE_FIRST;
         MQMessage myMessage    = new MQMessage();
         
         while(myMessage != null) {
            try {
               /***************************/
               /** Reset der Message-IDs **/
               /***************************/
               myMessage.clearMessage();
               myMessage.correlationId = MQC.MQCI_NONE;
               myMessage.messageId    = MQC.MQMI_NONE;
               
               /**********************/
               /** Message auslesen **/
               /**********************/
               myQueue.get(myMessage, gmo);
               String msg =
                  myMessage.readString(myMessage.getMessageLength());
               System.out.println("> " + msg);
               
               /********************************************************/
               /** Setzen der Optionen zum lesen der nächsten Message **/
               /********************************************************/
               gmo.options = MQC.MQGMO_WAIT | MQC.MQGMO_BROWSE_NEXT;
               
            } catch (MQException ex) {
               /*******************************************************/
               /** Schleife abbrechen, wenn keine Messages vorhanden **/
               /*******************************************************/
               if(ex.completionCode == 2 && ex.reasonCode == 2033) {
                  break;
               }
            } catch (IOException e) {
               System.out.println("Java Exception");
               e.printStackTrace();
            }
         }
         
         myQueue.close();
         qMgr.close();


Any help would be greatly appreciated!

Thx in advance

Björn
Back to top
View user's profile Send private message
mqonnet
PostPosted: Wed Sep 10, 2003 6:14 am    Post subject: Reply with quote

Grand Master

Joined: 18 Feb 2002
Posts: 1114
Location: Boston, Ma, Usa.

When you make any API call, it has to return some return code depending upon whether it was successful or a failure. Hence in this case, when you had messages, Reason code was 0 all the time. But when you dont have any messages and you make a get call, you get 2033. This is NOT AN ERROR. It just means that there were no messages on queue and you tried to GET messages.

Now as far as i know there is NO WAY to find out how many messages there are on the queue and loop it as many times. Unless your put app stores this number some place or you have some mechanism that would tell you how many messages you have put. Also bear in mind the queue is still available and even if you have a definite number, unless you are sure no one is accessing this queue and putting any further messages, you are bound to surprises.

Hence the elegant way is to catch this exception and just carry on. In this case, exception is NOT an ERROR.

Hope this helps.

Cheers
Kumar
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Björn
PostPosted: Wed Sep 10, 2003 6:51 am    Post subject: Reply with quote

Newbie

Joined: 10 Sep 2003
Posts: 7

Hi

thx for clearing this up for me a bit. However, the one thing that is causing the problem for me here, is that error message "MQJE001: Beendigungscode 2, Ursache 2033" which is NOT from my program. I'm just catching the Exception, printing "no more messages" and break the loop.
However, that "MQJE001: Beendigungscode 2, Ursache 2033 " is printed even BEFORE my own Exception-handling comes in, so it reads like this:

> MSG from Queue
> MSG from Queue
> MSG from Queue
MQJE001: Beendigungscode 2, Ursache 2033
no more messages

Any clue, where that error message might come from?

Thx in advance

Björn
Back to top
View user's profile Send private message
EddieA
PostPosted: Wed Sep 10, 2003 7:03 am    Post subject: Reply with quote

Jedi

Joined: 28 Jun 2001
Posts: 2453
Location: Los Angeles

It comes from the IBM classes. If you want to supress it:

Code:
      // Suppress the generated messages
      MQException.log = null;


Cheers,
_________________
Eddie Atherton
IBM Certified Solution Developer - WebSphere Message Broker V6.1
IBM Certified Solution Developer - WebSphere Message Broker V7.0
Back to top
View user's profile Send private message
mqonnet
PostPosted: Wed Sep 10, 2003 7:07 am    Post subject: Reply with quote

Grand Master

Joined: 18 Feb 2002
Posts: 1114
Location: Boston, Ma, Usa.

Well, that comes from the MQ Java bindings and you dont have any control over it. I don't know of a way of suppressing it. But other members might throw light on it.

But in general, thats the way it works. The error message that you got from MQ states that there was an exception with reason code 2033. Now what you do with that exception is your problem. And in your case you are just printing out some stuff if this occurs.


In any case why do you care if you do get this printed out. It has NO impact whatsover. Its just a message from MQ saying that there are no messages available.

Cheers
Kumar
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Björn
PostPosted: Wed Sep 10, 2003 7:23 am    Post subject: Reply with quote

Newbie

Joined: 10 Sep 2003
Posts: 7

Thx very much. That solves it. The reason why I care about this message is that I'd like my programs to run smoothly and with no error messages that aren't really errors. This program will be used by a few hundred clients of my company and they might panic if they see any error message

However, thank you both for your help and some insight into MQSeries API programming. I guess I'll be back soon with my next questions

Cheers

Björn
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 » Newbie problem browsing a queue
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.