Ibm mq WebhereMQ.net客户端一次获取多条消息

Ibm mq WebhereMQ.net客户端一次获取多条消息,ibm-mq,Ibm Mq,我使用WebPShereMQ和c客户端连接它。 可以在一个get方法中读取多条消息吗 如果不是,那么在mq中并行读取的最佳方式是什么 任何人都可以分享这方面的c示例。我的Mq版本是8您一次只能读取一条消息 下面是一个C示例,用于从“托管模式”下运行的队列中获取消息: using System; using System.Collections; using System.Collections.Generic; using System.Text; using IBM.WMQ; /// <

我使用WebPShereMQ和c客户端连接它。 可以在一个get方法中读取多条消息吗

如果不是,那么在mq中并行读取的最佳方式是什么


任何人都可以分享这方面的c示例。我的Mq版本是8

您一次只能读取一条消息

下面是一个C示例,用于从“托管模式”下运行的队列中获取消息:

using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using IBM.WMQ;

/// <summary> Program Name
/// MQTest02
///
/// Description
/// This C# class will connect to a remote queue manager
/// and get a message from a queue using a managed .NET environment.
///
/// Sample Command Line Parameters
/// -h 127.0.0.1 -p 1414 -c TEST.CHL -m MQA1 -q TEST.Q1 -u tester -x mypwd
/// </summary>
/// <author>  Roger Lacroix, Capitalware Inc.
/// </author>
namespace MQTest02
{
   class MQTest02
   {
      private Hashtable inParms = null;
      private Hashtable qMgrProp = null;
      private System.String qManager;
      private System.String outputQName;

      /*
      * The constructor
      */
      public MQTest02()
         : base()
      {
      }

      /// <summary> Make sure the required parameters are present.</summary>
      /// <returns> true/false
      /// </returns>
      private bool allParamsPresent()
      {
         bool b = inParms.ContainsKey("-h") && inParms.ContainsKey("-p") &&
                  inParms.ContainsKey("-c") && inParms.ContainsKey("-m") &&
                  inParms.ContainsKey("-q");
         if (b)
         {
            try
            {
               System.Int32.Parse((System.String)inParms["-p"]);
            }
            catch (System.FormatException e)
            {
               b = false;
            }
         }

         return b;
      }

      /// <summary> Extract the command-line parameters and initialize the MQ variables.</summary>
      /// <param name="args">
      /// </param>
      /// <throws>  IllegalArgumentException </throws>
      private void init(System.String[] args)
      {
         inParms = Hashtable.Synchronized(new Hashtable());
         if (args.Length > 0 && (args.Length % 2) == 0)
         {
            for (int i = 0; i < args.Length; i += 2)
            {
               inParms[args[i]] = args[i + 1];
            }
         }
         else
         {
            throw new System.ArgumentException();
         }

         if (allParamsPresent())
         {
            qManager = ((System.String)inParms["-m"]);
            outputQName = ((System.String)inParms["-q"]);

            qMgrProp = new Hashtable();
            qMgrProp.Add(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES_MANAGED);

            qMgrProp.Add(MQC.HOST_NAME_PROPERTY, ((System.String)inParms["-h"]));
            qMgrProp.Add(MQC.CHANNEL_PROPERTY, ((System.String)inParms["-c"]));

            try
            {
               qMgrProp.Add(MQC.PORT_PROPERTY, System.Int32.Parse((System.String)inParms["-p"]));
            }
            catch (System.FormatException e)
            {
               qMgrProp.Add(MQC.PORT_PROPERTY, 1414);
            }

            if (inParms.ContainsKey("-u"))
               qMgrProp.Add(MQC.USER_ID_PROPERTY, ((System.String)inParms["-u"]));

            if (inParms.ContainsKey("-x"))
               qMgrProp.Add(MQC.PASSWORD_PROPERTY, ((System.String)inParms["-x"]));

            System.Console.Out.WriteLine("MQTest02:");
            Console.WriteLine("  QMgrName ='{0}'", qManager);
            Console.WriteLine("  Output QName ='{0}'", outputQName);

            System.Console.Out.WriteLine("QMgr Property values:");
            foreach (DictionaryEntry de in qMgrProp)
            {
               Console.WriteLine("  {0} = '{1}'", de.Key, de.Value);
            }
         }
         else
         {
            throw new System.ArgumentException();
         }
      }

      /// <summary> Connect, open queue, read a message, close queue and disconnect.
      ///
      /// </summary>
      /// <throws>  MQException </throws>
      private void testReceive()
      {
         MQQueueManager qMgr = null;
         MQQueue queue = null;
         int openOptions = MQC.MQOO_INPUT_AS_Q_DEF + MQC.MQOO_FAIL_IF_QUIESCING;
         MQGetMessageOptions gmo = new MQGetMessageOptions();
         MQMessage receiveMsg = null;

         try
         {
            qMgr = new MQQueueManager(qManager, qMgrProp);
            System.Console.Out.WriteLine("MQTest02 successfully connected to " + qManager);

            queue = qMgr.AccessQueue(outputQName, openOptions, null, null, null); // no alternate user id
            System.Console.Out.WriteLine("MQTest02 successfully opened " + outputQName);

            receiveMsg = new MQMessage();

            queue.Get(receiveMsg, gmo);
            System.Console.Out.WriteLine("Message Data>>>" + receiveMsg.ReadString(receiveMsg.MessageLength));
         }
         catch (MQException mqex)
         {
            System.Console.Out.WriteLine("MQTest02 cc=" + mqex.CompletionCode + " : rc=" + mqex.ReasonCode);
         }
         catch (System.IO.IOException ioex)
         {
            System.Console.Out.WriteLine("MQTest02 ioex=" + ioex);
         }
         finally
         {
            try
            {
               queue.Close();
               System.Console.Out.WriteLine("MQTest02 closed: " + outputQName);
            }
            catch (MQException mqex)
            {
               System.Console.Out.WriteLine("MQTest02 cc=" + mqex.CompletionCode + " : rc=" + mqex.ReasonCode);
            }
            try
            {
               qMgr.Disconnect();
               System.Console.Out.WriteLine("MQTest02 disconnected from " + qManager);
            }
            catch (MQException mqex)
            {
               System.Console.Out.WriteLine("MQTest02 cc=" + mqex.CompletionCode + " : rc=" + mqex.ReasonCode);
            }
         }
      }

      /// <summary> main line</summary>
      /// <param name="args">
      /// </param>
      //        [STAThread]
      public static void Main(System.String[] args)
      {
         MQTest02 mqt = new MQTest02();

         try
         {
            mqt.init(args);
            mqt.testReceive();
         }
         catch (System.ArgumentException e)
         {
            System.Console.Out.WriteLine("Usage: MQTest02 -h host -p port -c channel -m QueueManagerName -q QueueName [-u userID] [-x passwd]");
            System.Environment.Exit(1);
         }
         catch (MQException e)
         {
            System.Console.Out.WriteLine(e);
            System.Environment.Exit(1);
         }

         System.Environment.Exit(0);
      }
   }
}

您好,罗杰,谢谢您的共享,如果您有,您可以将用户名密码登录代码共享到代码中吗?谢谢…我设置了用户名和密码,但执行失败。我缺少一些额外的信息,我想…我使用了您的代码,但队列中仍然出现2035错误。是否有其他属性,AUTHINFO对象上是否采用了CTXYES,有人说有一些类似的属性,但我可以在我的客户端代码中将它们设置到哪里打开队列管理器的“授权事件”,并查看队列管理器生成原因代码2035的原因。初始化用户ID“mypcuser”的调用失败,代码为2,原因为2035。如果使用了MQCSP块,则MQCSP块中的用户ID为“MyDifferentituser”User。操作:更正错误并重试。错误详细信息如此处所示,我的计算机用户没有权限,但我的设置serviceuser有权限。但我仍然收到这些错误