2016-05-06 61 views
0

你如何從客戶端所有可用的隊列名稱,使用IBM MQ LIB對於.NET(IBM.WMQ),版本的MQ環境的WebSphare MQ環境中的所有隊列名稱8.0? 我已經寫了一個很好的.Net應用程序來讀取和發送數據到MQ (similar founds at code project)無法獲得使用IBM .NET API

是否有人知道是否有可能/如何從IBM.WMQ .NET庫中動態獲取所有可用隊列名稱,就像使用工具IBM測試工具RfhUtil.exe時一樣,或者您可以使用來自IBM的runmqsc DISPLAY QUEUE命令.Net庫?

我試圖瀏覽API,Reference manualIBM programming guide沒有成功。

回答

0

PCFMessageAgent類在Java中,我可以看到一些似乎是指等價類的.NET的API中。

它可以構建自己的PCF消息,只要你有權限訪問SYSTEM.ADMIN.COMMAND.QUEUE

還需要動態地創建基於SYSTEM.COMMAND.REPLY.MODELSYSTEM.MQSC.REPLY.QUEUE回覆隊列。

1

還有就是在MQ .NET PCF支持一定的水平,但它是無證。以下是在隊列管理器中顯示隊列名稱的示例代碼。

using System; 
using System.Collections; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using IBM.WMQ; 
using IBM.WMQ.PCF; 

namespace PCFNET 
{ 
    class Program 
    { 
     static void Main(string[] args) 
     { 
      InquireQueue(); 
     } 

    /// <summary> 
    /// Display list of queue names and queue depth for each queue 
    /// </summary> 
    public static void InquireQueue() 
    { 
     PCFMessageAgent messageAgent = null; 
     try 
     { 
      // Create bindings connection to queue manager 
      messageAgent = new PCFMessageAgent("DEMOQMGR"); 

      // Build Inquire command to query queue name 
      PCFMessage reqeuestMessage = new PCFMessage(MQC.MQCMD_INQUIRE_Q); 
      reqeuestMessage.AddParameter(MQC.MQCA_Q_NAME, "*"); 

      // Send request and receive response 
      PCFMessage[] pcfResponse = messageAgent.Send(reqeuestMessage); 

      // Process and print response. 
      int pcfResponseLen = pcfResponse.Length; 
      for (int pcfResponseIdx = 0; pcfResponseIdx < pcfResponseLen; pcfResponseIdx++) 
      { 
       try 
       { 
        String qName = pcfResponse[pcfResponseIdx].GetStringParameterValue(MQC.MQCA_Q_NAME); 
        int qDepth = pcfResponse[pcfResponseIdx].GetIntParameterValue(MQC.MQIA_CURRENT_Q_DEPTH); 
        Console.WriteLine("QName: " + qName + " Depth: " + qDepth); 
       } 
       catch (PCFException pcfex) 
       { 
        //Ignore exception and get the next response 
       } 
      } 
     } 
     catch (PCFException pcfEx) 
     { 
      Console.Write(pcfEx); 
     } 
     catch (MQException ex) 
     { 
      Console.Write(ex); 
     } 
     catch (Exception ex) 
     { 
      Console.Write(ex); 
     } 
     finally 
     { 
      if (messageAgent != null) 
       messageAgent.Disconnect(); 
     } 
    } 
} 

}

+0

我得到QueueNameException(2058)錯誤調用InquireQueue()方法時。我試圖在建立活動會話(到其他隊列)時以及在使用有效連接數據創建MqQueueManager對象之後直接執行此操作。我在展位案例中遇到同樣的錯誤。拋出異常: 'IBM.WMQ.MQException' 在amqmdnet.dll,CompCode:2,原因是:2058調用InquireQueue當()梅託德。由於我建立了連接,我知道MQ的權利是正確的。我無法看到QueueManager名稱在InquireQueue()方法中與MQQueueManager中的相關。 –

+0

你在例子中忘了這個嗎? –

+0

該示例連接到本地隊列管理器DEMOQMGR,因爲您可以看到名稱傳遞給PCFMessageAgent類的構造函數。原因碼2058意味着隊列管理器名稱錯誤。您是否連接到本地隊列管理器或遠程隊列管理器。如果是遠程隊列管理器,那麼您需要通過提供通道名稱,主機和詩人編號來創建具有客戶端連接的MQQueueManager類實例。 – Shashi