Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. C# and IBM WebSphere MQ message borwsing

C# and IBM WebSphere MQ message borwsing

Scheduled Pinned Locked Moved C#
questioncsharpdata-structureshelptutorial
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    How Gee
    wrote on last edited by
    #1

    Hello, Can anyone help me, how can i browse the all messages in the queue? i have found several examples to get or put the messages, but about the browsing i haven't. The folloing example is browse the first messages, but i would like to see the all messages... MQQueueManager mqQMgr; MQQueue mqQueue; MQMessage mqMsg = new MQMessage(); MQGetMessageOptions mqGetMsgOpts = new MQGetMessageOptions(); mqQMgr = new MQQueueManager(qmName); mqQueue = mqQMgr.AccessQueue(qName, MQC.MQOO_BROWSE | MQC.MQGMO_LOGICAL_ORDER // open queue for browse + MQC.MQOO_FAIL_IF_QUIESCING); mqGetMsgOpts.Options = MQC.MQGMO_WAIT | MQC.MQGMO_BROWSE_FIRST; mqQueue.Get(mqMsg, mqGetMsgOpts); MessageBox.Show(mqMsg.ReadString(mqMsg.TotalMessageLength)); Thanx, Gee

    G 1 Reply Last reply
    0
    • H How Gee

      Hello, Can anyone help me, how can i browse the all messages in the queue? i have found several examples to get or put the messages, but about the browsing i haven't. The folloing example is browse the first messages, but i would like to see the all messages... MQQueueManager mqQMgr; MQQueue mqQueue; MQMessage mqMsg = new MQMessage(); MQGetMessageOptions mqGetMsgOpts = new MQGetMessageOptions(); mqQMgr = new MQQueueManager(qmName); mqQueue = mqQMgr.AccessQueue(qName, MQC.MQOO_BROWSE | MQC.MQGMO_LOGICAL_ORDER // open queue for browse + MQC.MQOO_FAIL_IF_QUIESCING); mqGetMsgOpts.Options = MQC.MQGMO_WAIT | MQC.MQGMO_BROWSE_FIRST; mqQueue.Get(mqMsg, mqGetMsgOpts); MessageBox.Show(mqMsg.ReadString(mqMsg.TotalMessageLength)); Thanx, Gee

      G Offline
      G Offline
      Gavin Jerman
      wrote on last edited by
      #2

      Replace MQC.MQGMO_BROWSE_FIRST with MQC.MQGMO_BROWSE_NEXT and call Get in a loop until it fails - it will throw a harmless exception with a reason code of MQRC_NO_MSG_AVAILABLE when there are no more messages to browse. I would also suggest that you use MQGMO_NO_WAIT rather than MQGMO_WAIT so that you don't have to wait until a message appears on the queue when you browse an empty queue. Example code using home-brewed helper methods:

      public bool browseMessages(out ArrayList messages, string queue)
      {
      // browse (i.e. get without removing) a message on the message queue
      messages = new ArrayList();
      MQQueueManager mqQM = null;
      MQQueue mqQ = null;

        try
        {
          if (queue == null || queue.Length == 0)
            throw new Exception("Queue name required");
      
          // connect to queue manager
          connectManager(out mqQM);
      
          // open queue with required access
          connectQueue(mqQM, queue, MQC.MQOO\_FAIL\_IF\_QUIESCING + MQC.MQOO\_BROWSE, out mqQ);
      
          // get message options
          MQGetMessageOptions mqGMO = new MQGetMessageOptions();
          mqGMO.Options = MQC.MQGMO\_FAIL\_IF\_QUIESCING + MQC.MQGMO\_NO\_WAIT + MQC.MQGMO\_BROWSE\_NEXT; // browse with no wait
          mqGMO.MatchOptions = MQC.MQMO\_NONE; // no matching required
      
          MQMessage mqMsg = new MQMessage(); // object to receive the message
      
          // browse all messages on the queue
          while (true)
          {
            // browse message - exception will be thrown when no more messages
            mqQ.Get(mqMsg, mqGMO);
      
            // get message text from the message object
            messages.Add(mqMsg.ReadString(mqMsg.MessageLength));
          }
        }
        catch (MQException mqex)
        {
          if (mqex.ReasonCode == MQC.MQRC\_NO\_MSG\_AVAILABLE)
          {
            // harmless exception MQ throws to indicate that there are no messages on the queue
            return true;
          }
          else
            throwMQException(mqex);
        }
        finally
        {
          if (mqQ != null)
            mqQ.Close();
      
          if (mqQM != null)
            mqQM.Disconnect();
        }
      
        return false;
      }
      

      Gavin

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups