簡體   English   中英

嘗試使用C#從MQ獲取消息時出現錯誤?

[英]Getting Error while trying to GET message from MQ using C#?

我正在嘗試使用來自Asp.net的Web Sphere MQ在隊列管理器中放入和獲取消息。 以下是我的代碼。 我收到錯誤2033 MQRC_NO_MSG_AVAILABLE我從隊列中讀取消息時我做錯了什么。 預先感謝

using System;
using System.Collections.Generic;
using System.Text;
using IBM.WMQ;
using System.Collections;
namespace JMS_IBM
{
    class Program
    {

        const String connectionType = MQC.TRANSPORT_MQSERIES_CLIENT;
         // Define the name of the queue manager to use (applies to all connections)
        const String qManager = "XXXXX";
         // Define the name of your host connection (applies to client connections only)
        const String hostName = "XX.XX.XX.XX(XXXX)";
         // Define the name of the channel to use (applies to client connections only)
        const String channel = "SYSTEM.DEF.SVRCONN";

 static Hashtable init(String connectionType)
        {
            Hashtable connectionProperties = new Hashtable();

            // Add the connection type
            connectionProperties.Add(MQC.TRANSPORT_PROPERTY, connectionType);

            // Set up the rest of the connection properties, based on the
            // connection type requested
            switch (connectionType)
            {
                case MQC.TRANSPORT_MQSERIES_BINDINGS:
                    break;
                case MQC.TRANSPORT_MQSERIES_CLIENT:
                case MQC.TRANSPORT_MQSERIES_XACLIENT:
                case MQC.TRANSPORT_MQSERIES_MANAGED:
                    connectionProperties.Add(MQC.HOST_NAME_PROPERTY, hostName);
                    connectionProperties.Add(MQC.CHANNEL_PROPERTY, channel);
                    break;
            }

            return connectionProperties;
        }

        static int Main(string[] args)
        {
            try
            {
                Hashtable connectionProperties = init(connectionType);

                // Create a connection to the queue manager using the connection
                // properties just defined
                MQQueueManager qMgr = new MQQueueManager(qManager, connectionProperties);

                // Set up the options on the queue we want to open
                int openOptions = MQC.MQOO_OUTPUT | MQC.MQOO_FAIL_IF_QUIESCING;
                //MQC.MQOO_INPUT_AS_Q_DEF | MQC.MQOO_OUTPUT;

                // Now specify the queue that we want to open,and the open options
                MQQueue system_default_local_queue =
                  qMgr.AccessQueue("SC.CRM.SVC.RQI.01", openOptions);

                // Define a WebSphere MQ message, writing some text in UTF format
                MQMessage hello_world = new MQMessage();
                //hello_world.WriteUTF("Hello World!");
                //01244269211
                string msg = "XML";

                hello_world.WriteString(msg);

                // Specify the message options
                MQPutMessageOptions pmo = new MQPutMessageOptions(); // accept the defaults,
                // same as MQPMO_DEFAULT

                // Put the message on the queue
                system_default_local_queue.Put(hello_world, pmo);

                hello_world.CorrelationId = hello_world.MessageId;
                //retrievedMessage.CorrelationId = hello_world.MessageId;

                // Set the get message options
                MQGetMessageOptions gmo = new MQGetMessageOptions(); //accept the defaults
                //same as MQGMO_DEFAULT
                int readOptions = MQC.MQOO_INPUT_AS_Q_DEF | MQC.MQOO_FAIL_IF_QUIESCING;

                MQQueue system_default_local_queue_OT =  qMgr.AccessQueue("SC.CRM.SVC.RPO.01", readOptions);

                gmo.Options = MQC.MQGMO_WAIT | MQC.MQOO_FAIL_IF_QUIESCING;
                //gmo.MatchOptions = MQC.MQMO_MATCH_CORREL_ID;
                gmo.MatchOptions = MQC.MQMO_NONE;
                gmo.WaitInterval = 5000;

             //   retrievedMessage.CorrelationId = retrievedMessage.MessageId;
                // Get the message off the queue
                system_default_local_queue_OT.Get(hello_world, gmo);

                // Prove we have the message by displaying the UTF message text
                String msgText = hello_world.ReadUTF();
                Console.WriteLine("The message is: {0}", msgText);

                // Close the queue
                system_default_local_queue.Close();

                // Disconnect from the queue manager
                qMgr.Disconnect();
            }

            catch (MQException ex)
            {
                Console.WriteLine("A WebSphere MQ error occurred: {0}", ex.ToString());
            }

            catch (System.Exception ex)
            {
                Console.WriteLine("A System error occurred: {0}", ex.ToString());
            }

            return 0;
        }//end of start
    }

}

如您所知2033 0x000007f1 MQRC_NO_MSG_AVAILABLE ..所以您做的一切似乎都是正確的,但是隊列管理器端Q中似乎沒有味精。.請確認您在Q中是否有味精並且仍然得到此信息?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM