共用方式為


佇列管理支援

透過BizTalk Server MQSeries 配接器,您現在可以在 MQSeries 佇列管理員上遠端建立和刪除佇列。 支援此功能,因為BizTalk Server使用與 MQSeries 佇列管理員直接通訊的遠端 MQSAgent COM+ 物件。 通常此 MQSAgent 是在執行階段用來讀取與寫入遠端 MQSeries Server 佇列的訊息。 此遠端服務同時可支援一個以上的 BizTalk Server 作為其用戶端。 此外,佇列的建立與刪除功能都是由此 MQSAgent 提供,可以從協調流程或配接器中直接呼叫。 這樣一來,協調流程或配接器可以建立臨時佇列,然後用它來傳送訊息、接收另一個佇列的回應,並最終刪除臨時佇列,形成一個高度動態的實例。

CreateQueue 與 DeleteQueue 等 API

CreateQueue 與 DeleteQueue 等 API 的定義如下所示:

結構定義

typedef enum QueueUsage {  
      Normal       = 0,  
      Transmission = 1  
} QueueUsage;  
  
typedef enum ResultCode {  
      QueueAlreadyExists                     = 0, //  no bits set  
      QueueCreated                           = 1, //  QueueCreated  
      QueueCreatedAndRemoteDefinitionUpdated = 5, //  QueueCreated | RemoteDefinitionUpdated  
      QueueAndRemoteDefinitionCreated        = 7, //  QueueCreated | RemoteDefinitionCreated | RemoteDefinitionUpdated  
      QueueDoesNotExist                      = 8, //  QueueDoesNotExist  
      QueueDeleted                           = 16 //  QueueDeleted  
} ResultCode;  

介面定義

[  
            object,  
            uuid(E90AC1A6-657B-4680-AF6A-89F11113FB8B),  
            dual,  
            nonextensible,  
            helpstring("IMQSAdmin Interface"),  
            pointer_default(unique)  
]  
interface IMQSAdmin2 : IDispatch{  
  
HRESULT CreateQueue (  
[in]BSTR queueManager,  
[in]BSTR newQueueName,  
[in]QueueUsage usage,  
[in]BSTR remoteDefinition,  
[in]BSTR remoteQName,  
[in]BSTR remoteQMgrName,  
[in]BOOL updateExistingRemoteDefinition,  
[out, retval]ResultCode* resultCode);  
  
HRESULT DeleteQueue (  
[in]BSTR queueManager,  
[in]BSTR newQueueName,  
[out, retval]ResultCode* resultCode);  
};  
  
      [  
            uuid(412AF00D-7CA8-4d2a-AFF6-F61CE2E29A0D),  
            helpstring("MQSAdmin Class")  
      ]  
      coclass MQSAdmin  
      {  
            [default] interface IMQSAdmin2;  
      };  
  

範例

完成範例 1 中的步驟,以建立可用來建立或刪除 MQSeries 伺服器佇列的 Visual Studio C# 主控台應用程式。

範例 1

建立 C# 主控台應用程式以管理 MQSeries Server 佇列
  1. 在 Visual Studio 中建立名為 MQSeriesQueues的新 Visual C# 主控台應用程式。

  2. 以下列程式碼取代所產生 Program.cs 檔案中的任何現有程式碼:

    using System;  
    using System.Collections.Generic;  
    using System.Text;  
    using MQSAgentLib;  
    
    namespace MQSeriesQueues  
    {  
        class ManageQueues  
        {  
            public static void Main(string[] args)  
            {  
                // The first argument should be "c" (without quotes)  
                // to create a queue, anything else to delete a queue.  
                // The 2nd and 3rd arguments should be the name of   
                // the MQSeries Queue Manager and the name of   
                // the queue to be created or deleted for example  
                // the following usage will create the local   
                // queue testq for the Queue Manager QM_Test  
                // MQSeriesQueues c QM_Test testq  
                createordeleteQs(args[0], args[1], args[2]);  
            }  
    
            static void createordeleteQs(string Qswitch, string QMgr, string QName)  
            {   
            if ((Qswitch =="c" & (QMgr != null & QName != null)))  
                {  
                    CreateQueue(QMgr, QName);  
                }  
                else if(QMgr != null & QName != null)  
                {  
                    DeleteQueue(QMgr, QName);  
                }  
             }  
    
            static void CreateQueue(string Qmgr, string Qname)  
            {  
                MQSAdmin admin = new MQSAdmin();    
    
                ResultCode resultCode = admin.CreateQueue(Qmgr, Qname, 0, "", "", "", 0);  
    
                if ((resultCode & ResultCode.QueueCreated) == ResultCode.QueueCreated)  
                {  
                    Console.WriteLine("Queue Created.");  
                }  
                else if ((resultCode & ResultCode.QueueAlreadyExists) == ResultCode.QueueAlreadyExists)  
                {  
                    Console.WriteLine("Queue Already Exists.");  
                }  
            }  
    
            static void DeleteQueue(string Qmgr, string Qname)  
            {  
                MQSAdmin admin = new MQSAdmin();  
    
                ResultCode resultCode = admin.DeleteQueue(Qmgr, Qname);  
    
                if ((resultCode & ResultCode.QueueDeleted) == ResultCode.QueueDeleted)  
                {  
                    Console.WriteLine("Queue successfully deleted.");  
                }  
                if ((resultCode & ResultCode.QueueDoesNotExist) == ResultCode.QueueDoesNotExist)  
                {  
                    Console.WriteLine("Queue did not exist anyway!");  
                }  
            }  
    
        }  
    }  
    
  3. 將這個專案的參考新增至 MQSAgent 1.0 型別程式庫MQSAgent 1.0 型別程式庫可在 [新增參考] 對話方塊的[COM] 索引標籤上取得。

    注意

    其中正在執行此主控台應用程式的電腦,必須安裝 MQSAgent COM+ 元件。 如需安裝 MQSAgent COM+ 元件的詳細資訊,請參閱 使用 MQSAgent COM+ 設定精靈

  4. 建置主控台應用程式。

  5. 開啟命令提示字元,移至已編譯主控台應用程式的相同目錄。

  6. 輸入已編譯主控台應用程式的名稱加上適當的參數,然後按 ENTER。 例如,若要刪除佇列管理員的佇列testq,QM_Test您會在命令提示字元中輸入下列文字,然後按 ENTER:

    MQSeriesQueues d QM_Test testq  
    
  7. 若要建立佇列管理員的佇列 testqQM_Test 您會在命令提示字元中輸入下列文字,然後按 ENTER 鍵:

    MQSeriesQueues c QM_Test testq