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 » Browse help

Post new topic  Reply to topic
 Browse help « View previous topic :: View next topic » 
Author Message
Yars13
PostPosted: Fri Oct 15, 2004 10:02 am    Post subject: Browse help Reply with quote

Novice

Joined: 27 Sep 2004
Posts: 21

Hi, i'm writing code to browse a queue that i know for a fact has some messages on it. The problem is i keep getting a 2033 error, which according to IBM means that there are no messages available. Maybe i'm using wrong options, i'm not sure. Here is my code, maybe someone can point out what i'm doing wrong. Thanks
Code:

using System;
using IBM.WMQ;


namespace browse
{
   /// <summary>
   /// Summary description for Class1.
   /// </summary>
   class Class1
   {
      /// <summary>
      /// The main entry point for the application.
      /// </summary>
      [STAThread]
      static void Main(string[] args)
      {
         try
         {
            MQQueueManager queueManager = new MQQueueManager("mgr", "channel", "10.124.219.23(6598)");
            int openOptions = MQC.MQOO_BROWSE + MQC.MQOO_INQUIRE + MQC.MQOO_FAIL_IF_QUIESCING + MQC.MQOO_INPUT_SHARED;
            MQQueue queue = queueManager.AccessQueue("STNQM.FROM.JPMC", openOptions);

            //set up our options to browse for the first message
            MQGetMessageOptions gmo = new MQGetMessageOptions();
            gmo.Options = MQC.MQGMO_BROWSE_FIRST;
            MQMessage message = new MQMessage();

            //get next
            bool done = false;
            int count = 0;
            do
            {
               try
               {
                  //clear the message
                  message.ClearMessage();

                  //browse the message and display it
                  queue.Get(message, gmo);
                  string msg = message.ReadString(message.MessageLength);
                  Console.WriteLine("Message #" + count++ + ": " + msg);

                  gmo.Options = MQC.MQGMO_BROWSE_NEXT + MQC.MQGMO_NO_WAIT + MQC.MQGMO_FAIL_IF_QUIESCING + MQC.MQGMO_CONVERT;

               }
               catch(MQException ex)
               {
                  Console.WriteLine("Error: " + ex.Message);
                  //should be an error 2033 b/c there are no more messages on queue.
                  done = true;
               }
            }while(!done);

            Console.ReadLine();
         }
         catch (MQException ex)
         {
            Console.WriteLine("Error: " + ex.Message);
         }
      }
   }
}
Back to top
View user's profile Send private message
Yars13
PostPosted: Fri Oct 15, 2004 10:45 am    Post subject: Reply with quote

Novice

Joined: 27 Sep 2004
Posts: 21

ok i lied:) I added a line of code to return the number of messages currently on the queue and it returns the correct number, but the problem i'm still having is that it's only returning the first message and then says that there are no more messages on the queue.

I'm sure i'm just doing something really stupid in my code and just can't see it. Any help is appreciated. Thanks

Yars
Back to top
View user's profile Send private message
Yars13
PostPosted: Fri Oct 15, 2004 10:58 am    Post subject: Reply with quote

Novice

Joined: 27 Sep 2004
Posts: 21

One more thing to add, according to the examples i've seen for java right after i say message.ClearMessage(), i should set messageID and correlationID to MQC.MQCI_NONE. The .Net manual even says that this is an option. But for some reason i get an error that says that this option is not part of IBM.WMQ. Any ideas why?

Yars
Back to top
View user's profile Send private message
vennela
PostPosted: Sat Oct 16, 2004 6:47 pm    Post subject: Reply with quote

Jedi Knight

Joined: 11 Aug 2002
Posts: 4055
Location: Hyderabad, India

Instead of clearing the message move the MQMessage object instantiation inside the try block.

Try this

Code:

using System;
using IBM.WMQ;


namespace browse
{
   /// <summary>
   /// Summary description for Class1.
   /// </summary>
   class Class1
   {
      /// <summary>
      /// The main entry point for the application.
      /// </summary>
      [STAThread]
      static void Main(string[] args)
      {
         try
         {
            MQQueueManager queueManager = new MQQueueManager("mgr", "channel", "10.124.219.23(6598)");
            int openOptions = MQC.MQOO_BROWSE + MQC.MQOO_INQUIRE + MQC.MQOO_FAIL_IF_QUIESCING + MQC.MQOO_INPUT_SHARED;
            MQQueue queue = queueManager.AccessQueue("STNQM.FROM.JPMC", openOptions);

            //set up our options to browse for the first message
            MQGetMessageOptions gmo = new MQGetMessageOptions();
            gmo.Options = MQC.MQGMO_BROWSE_FIRST;
            //get next
            bool done = false;
            int count = 0;
            do
            {
               try
               {
                  //clear the message
            MQMessage message = new MQMessage();

                  //browse the message and display it
                  queue.Get(message, gmo);
                  string msg = message.ReadString(message.MessageLength);
                  Console.WriteLine("Message #" + count++ + ": " + msg);

                  gmo.Options = MQC.MQGMO_BROWSE_NEXT + MQC.MQGMO_NO_WAIT + MQC.MQGMO_FAIL_IF_QUIESCING + MQC.MQGMO_CONVERT;

               }
               catch(MQException ex)
               {
                  Console.WriteLine("Error: " + ex.Message);
                  //should be an error 2033 b/c there are no more messages on queue.
                  done = true;
               }
            }while(!done);

            Console.ReadLine();
         }
         catch (MQException ex)
         {
            Console.WriteLine("Error: " + ex.Message);
         }
      }
   }
}
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Yars13
PostPosted: Mon Oct 18, 2004 4:17 am    Post subject: Reply with quote

Novice

Joined: 27 Sep 2004
Posts: 21

Thank you, that worked.

Yars
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 API Support » Browse help
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.