從 Azure Logic Apps 連線到 IBM MQ 伺服器Connect to an IBM MQ server from Azure Logic Apps

MQ 連接器會傳送和取出儲存在 MQ server 內部部署或 Azure 中的訊息。The MQ connector sends and retrieves messages stored in an MQ server on premises or in Azure. 此連接器包含透過 TCP/IP 網路與遠端 IBM MQ Server 通訊的 Microsoft MQ 用戶端。This connector includes a Microsoft MQ client that communicates with a remote IBM MQ server across a TCP/IP network. 本文提供使用 MQ 連接器的入門指南。This article provides a starter guide to use the MQ connector. 您可以從瀏覽佇列上的單一訊息開始,然後再嘗試其他動作。You can start by browsing a single message on a queue and then try other actions.

MQ 連接器包含這些動作,但不提供任何觸發程式:The MQ connector includes these actions but provides no triggers:

  • 流覽單一訊息,而不刪除 MQ server 中的訊息。Browse a single message without deleting the message from the MQ server.
  • 流覽訊息批次,而不刪除 MQ server 中的訊息。Browse a batch of messages without deleting the messages from the MQ server.
  • 接收單一訊息,並從 MQ server 刪除訊息。Receive a single message and delete the message from the MQ server.
  • 接收一批訊息,並從 MQ server 刪除訊息。Receive a batch of messages and delete the messages from the MQ server.
  • 傳送單一訊息至 MQ 伺服器。Send a single message to the MQ server.

以下是正式支援的 IBM WebSphere MQ 版本:Here are the officially supported IBM WebSphere MQ versions:

  • MQ 7.5MQ 7.5
  • MQ 8.0MQ 8.0
  • MQ 9.0MQ 9.0
  • MQ 9.1MQ 9.1

PrerequisitesPrerequisites

  • 如果您使用內部部署 MQ server,則需要在網路內的伺服器上 安裝內部部署資料閘道If you use an on-premises MQ server, you need to install the on-premises data gateway on a server within your network.

    注意

    如果您的 MQ 伺服器已在 Azure 中正式推出或提供,您就不需要使用資料閘道。If your MQ server is publicly available or available within Azure, you don't have to use the data gateway.

    • 若要讓 MQ connector 能夠運作,您安裝內部部署資料閘道的伺服器也需要安裝 .NET Framework 4.6。For the MQ connector to work, the server where you install the on-premises data gateway also needs to have .NET Framework 4.6 installed.

    • 安裝內部部署資料閘道之後,您也需要為 MQ connector 用來存取內部部署 MQ server 的內部 部署資料閘道建立 Azure 閘道資源After you install the on-premises data gateway, you also need to create an Azure gateway resource for the on-premises data gateway that the MQ connector uses to access your on-premises MQ server.

  • 您要在其中使用 MQ 連接器的邏輯應用程式。The logic app where you want to use the MQ connector. MQ 連接器沒有任何觸發程序,因此您必須先將觸發程序新增至邏輯應用程式。The MQ connector doesn't have any triggers, so you must add a trigger to your logic app first. 例如,您可以使用 迴圈觸發程式。For example, you can use the Recurrence trigger. 如果您還不熟悉邏輯應用程式,請參閱快速入門:建立第一個邏輯應用程式If you're new to logic apps, try this quickstart to create your first logic app.

限制Limitations

MQ 連接器不支援或使用訊息的 Format 欄位,也不會執行任何字元集轉換。The MQ connector doesn't support or use the message's Format field and doesn't perform any character set conversions. 連接器只會將訊息欄位中出現的任何資料放入 JSON 訊息中,並連同傳送訊息。The connector only puts whatever data appears in the message field into a JSON message and sends the message along.

建立 MQ 連線Create MQ connection

當您新增 MQ 動作時,如果您還沒有 MQ 連線,系統會提示您建立連線,例如:If you don't already have an MQ connection when you add an MQ action, you're prompted to create the connection, for example:

提供連線資訊

  1. 如果您要連線到內部部署 MQ 伺服器,請選取 [透過內部部署資料閘道連線]。If you're connecting to an on-premises MQ server, select Connect via on-premises data gateway.

  2. 提供 MQ 伺服器的連線資訊。Provide the connection information for your MQ server.

    • 針對 [伺服器],您可以輸入 MQ Server 的名稱,或輸入 IP 位址,後面接著冒號和連接埠號碼。For Server, you can enter the MQ server name, or enter the IP address followed by a colon and the port number.

    • 若要使用傳輸層安全性 (TLS) 或安全通訊端層 (SSL) ,請選取 [ 啟用 ssl]。To use Transport Layer Security (TLS) or Secure Sockets Layer (SSL), select Enable SSL?.

      MQ 連接器目前僅支援「伺服器驗證」,不支援「用戶端驗證」。The MQ connector currently supports only server authentication, not client authentication. 如需詳細資訊,請參閱連線和驗證問題For more information, see Connection and authentication problems.

  3. 在 [閘道] 區段中,依照下列步驟執行:In the gateway section, follow these steps:

    1. 用帳戶清單中,選取與您的 azure 閘道資源相關聯的 azure 訂用帳戶。From the Subscription list, select the Azure subscription that's associated with your Azure gateway resource.

    2. 從 [連線閘道] 清單中,選取您想要使用的 Azure 閘道資源。From the Connection Gateway list, select the Azure gateway resource that you want to use.

  4. 當您完成時,選取 [建立]。When you're done, select Create.

連線和驗證問題Connection and authentication problems

當您的邏輯應用程式嘗試連線到您的內部部署 MQ 伺服器時,您可能會收到此錯誤:When your logic app tries connecting to your on-premises MQ server, you might get this error:

"MQ: Could not Connect the Queue Manager '<queue-manager-name>': The Server was expecting an SSL connection."

  • 如果您,是直接在 Azure 中使用 MQ 連接器,MQ 伺服器就必須使用由受信任的憑證授權單位發行的憑證。If you're using the MQ connector directly in Azure, the MQ server needs to use a certificate that's issued by a trusted certificate authority.

  • 如果您是使用內部部署資料閘道,可能的話,請嘗試使用由受信任的憑證授權單位發行的憑證。If you're using the on-premises data gateway, try to use a certificate that's issued by a trusted certificate authority when possible. 不過,如果無法採取此做法,您可以使用自我簽署的憑證,這不是由受信任的憑證授權單位發行,而且被視為較不安全。However, if this option isn't possible, you could use a self-signed certificate, which is isn't issued by a trusted certificate authority and is considered less secure.

    若要安裝伺服器的自我簽署憑證,您可以使用 Windows 認證管理員 (certmgr.msc) 工具。To install the server's self-signed certificate, you can use the Windows Certification Manager (certmgr.msc) tool. 此案例中,在內部部署資料閘道服務執行所在的本機電腦上,您必須在 本機電腦 憑證存放區的 信任的根憑證授權單位 層級安裝憑證。For this scenario, on your local computer where the on-premises data gateway service is running, you need to install the certificate in your Local Computer certificates store at the Trusted Root Certification Authorities level.

    1. 在內部部署資料閘道服務執行所在的電腦上,開啟 [開始] 功能表,尋找並選取 [管理使用者憑證]。On the computer where the on-premises-data gateway service is running, open the start menu, find and select Manage user certificates.

    2. 在 [Windows 認證管理員] 工具開啟之後,移至 [憑證-本機電腦] > [信任的根憑證授權單位] 資料夾,然後安裝憑證。After the Windows Certification Manager tool opens, go to the Certificates - Local Computer > Trusted Root Certification Authorities folder, and install the certificate.

      重要

      請確定您將憑證安裝在 [憑證-本機電腦] > [信任的根憑證授權單位] 存放區。Make sure that you install certificate in the Certificates - Local Computer > Trusted Root Certification Authorities store.

  • MQ server 需要您定義要用於 TLS/SSL 連線的密碼規格。The MQ server requires that you define the cipher specification that you want to use for TLS/SSL connections. 不過,.NET 中的 SslStream 不允許您指定密碼規格的順序。However, SslStream in .NET doesn't permit you to specify the order for cipher specifications. 若要解決這項限制,您可以變更 MQ 伺服器設定,使其符合套件中的第一個加密規格(連接器會在 TLS/SSL 協商中傳送)。To work around this limitation, you can change your MQ server configuration to match the first cipher specification in the suite that the connector sends in the TLS/SSL negotiation.

    當您嘗試連線時,MQ 伺服器會記錄事件訊息,其中指出連線失敗是因為另一端使用了不正確的加密規格。When you try the connection, the MQ server logs an event message that indicates the connection failed because the other end used the incorrect cipher specification. 事件訊息包含第一個出現在清單中的加密規格。The event message contains the cipher specification that appears first in the list. 更新通道設定中的加密規格,以符合事件訊息中的加密規格。Update the cipher specification in the channel configuration to match the cipher specification in the event message.

瀏覽單一訊息Browse single message

  1. 在邏輯應用程式的觸發程序或其他動作底下,選取 [新增步驟]。In your logic app, under the trigger or another action, select New step.

  2. 在 [搜尋] 方塊中,輸入 mq,然後選取 [瀏覽訊息] 動作。In the search box, enter mq, and select the Browse message action.

    選取 [瀏覽訊息] 動作

  3. 如果您尚未建立 MQ 連線,系統會提示您建立連線If you haven't already created an MQ connection, you're prompted to create that connection.

  4. 建立連線之後,設定 [瀏覽訊息] 動作的屬性:After you create the connection, set up the Browse message action's properties:

    屬性Property 描述Description
    佇列Queue 如果與連線中指定的佇列不同,請指定該佇列。If different from the queue specified in the connection, specify that queue.
    MessageIdCorrelationIdGroupId 和其他屬性MessageId, CorrelationId, GroupId, and other properties 依據不同的 MQ 訊息屬性瀏覽其他訊息Browse for a message that's based on the different MQ message properties
    IncludeInfoIncludeInfo 若要在輸出中包含額外訊息資訊,請選取 trueTo include additional message information in the output, select true. 若要在輸出中省略額外訊息資訊,請選取 falseTo omit additional message information in the output, select false.
    逾時Timeout 輸入一個值,來決定等候訊息到達空白佇列的等候時間。Enter a value to determine how long to wait for a message to arrive in an empty queue. 如果未輸入任何內容,就會取出佇列中的第一個訊息,且不會花費時間等候要顯示的訊息。If nothing is entered, the first message in the queue is retrieved, and there is no time spent waiting for a message to appear.

    例如:For example:

    [瀏覽訊息] 動作的屬性

  5. 完成時,請在設計工具的工具列上,選取 [儲存]。When you're done, on the designer toolbar, select Save. 若要測試您的應用程式,請選取 [執行行]。To test your app, select Run.

    執行完成之後,設計工具會顯示工作流程步驟及其狀態,讓您可以查看輸出。After the run finishes, the designer shows the workflow steps and their status so that you can review the output.

  6. 若要檢視每個步驟的詳細資料,按一下步驟的標題列。To view the details about each step, click the step's title bar. 若要查看步驟的輸出詳細資訊,選取 [顯示原始輸出]。To review more information about a step's output, select Show raw outputs.

    瀏覽訊息輸出

    以下是一些範例原始輸出:Here is some sample raw output:

    瀏覽訊息原始輸出

  7. 如果您將 IncludeInfo 設定為 true,則會顯示額外輸出:If you set IncludeInfo to true, additional output is shown:

    瀏覽訊息包含資訊

瀏覽多個訊息Browse multiple messages

[瀏覽多個訊息] 動作有 BatchSize 選項,可指出應該從佇列傳回的訊息數量。The Browse messages action includes a BatchSize option to indicate how many messages to return from the queue. 如果 BatchSize 沒有值,就會傳回所有的訊息。If BatchSize has no value, all messages are returned. 傳回的輸出是陣列訊息。The returned output is an array of messages.

  1. 遵循先前的步驟,但改為新增 瀏覽多個訊息 動作。Follow the previous steps, but add the Browse messages action instead.

  2. 如果您尚未建立 MQ 連線,系統會提示您建立連線If you haven't already created an MQ connection, you're prompted to create that connection. 否則,預設會使用第一個先前設定的連線。Otherwise, by default, the first previously configured connection is used. 若要建立新的連線,選取 [變更連線]。To create a new connection, select Change connection. 或者,選取其他的連線。Or, select a different connection.

  3. 提供動作的資訊。Provide the information for the action.

  4. 儲存並執行邏輯應用程式。Save and run the logic app.

    邏輯應用程式完成執行之後,以下是 [瀏覽多個訊息] 動作的一些範例輸出:After the logic app finishes running, here is some sample output from the Browse messages action:

    瀏覽多個訊息輸出範例

接收單一訊息Receive single message

[接收訊息] 動作具有與 [瀏覽訊息] 動作相同的輸入和輸出。The Receive message action has the same inputs and outputs as the Browse message action. 當您使用 [接收訊息] 時,系統會從佇列中將訊息刪除。When you use Receive message, the message is deleted from the queue.

接收多個訊息Receive multiple messages

[接收訊息] 動作具有與 [瀏覽訊息] 動作相同的輸入和輸出。The Receive messages action has the same inputs and outputs as the Browse messages action. 當您使用 [接收多個訊息] 時,系統會從佇列中將多個訊息刪除。When you use Receive messages, the messages are deleted from the queue.

注意

在沒有任何訊息的佇列上執行瀏覽或接收動作時,動作會失敗,並顯示下列輸出:When running a browse or a receive action on a queue that doesn't have any messages, the action fails with this output:

MQ 無訊息錯誤

傳送訊息Send message

  1. 遵循先前的步驟,但改為新增 傳送訊息 動作。Follow the previous steps, but add the Send message action instead.

  2. 如果您尚未建立 MQ 連線,系統會提示您建立連線If you haven't already created an MQ connection, you're prompted to create that connection. 否則,預設會使用第一個先前設定的連線。Otherwise, by default, the first previously configured connection is used. 若要建立新的連線,選取 [變更連線]。To create a new connection, select Change connection. 或者,選取其他的連線。Or, select a different connection.

  3. 提供動作的資訊。Provide the information for the action. 針對 [MessageType],請選取有效的訊息類型:DatagramReplyRequestFor MessageType, select a valid message type: Datagram, Reply, or Request

    傳送訊息動作的屬性

  4. 儲存並執行邏輯應用程式。Save and run the logic app.

    邏輯應用程式完成執行之後,以下是 [傳送訊息] 動作的一些範例輸出:After the logic app finishes running, here is some sample output from the Send message action:

    傳送訊息輸出範例

連接器參考Connector reference

如需技術詳細資料(例如,連接器的 Swagger 檔案中所述的動作和限制),請參閱 連接器的參考頁面For technical details, such as actions and limits, which are described in the connector's Swagger file, review the connector's reference page.

後續步驟Next steps