从 Azure 逻辑应用连接到 IBM MQ 服务器Connect to an IBM MQ server from Azure Logic Apps

IBM MQ 连接器会发送和检索存储在 IBM MQ 服务器本地或 Azure 中的消息。The IBM MQ connector sends and retrieves messages stored in an IBM MQ server on premises or in Azure. 此连接器包括要在 TCP/IP 网络上与远程 IBM MQ 服务器计算机通信的 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.

IBM MQ 连接器包含以下操作,但不提供触发器:The IBM MQ connector includes these actions but provides no triggers:

  • 浏览单条消息,而不从 IBM MQ 服务器中删除该消息。Browse a single message without deleting the message from the IBM MQ server.
  • 浏览一批消息,而不从 IBM MQ 服务器中删除这些消息。Browse a batch of messages without deleting the messages from the IBM MQ server.
  • 接收单条消息,并从 IBM MQ 服务器中删除该消息。Receive a single message and delete the message from the IBM MQ server.
  • 接收一批消息,并从 IBM MQ 服务器中删除这些消息。Receive a batch of messages and delete the messages from the IBM MQ server.
  • 将单条消息发送到 IBM MQ 服务器。Send a single message to the IBM 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

先决条件Prerequisites

  • 如果使用本地 MQ 服务器,则在网络中的服务器上安装本地数据网关If you're using an on-premises MQ server, install the on-premises data gateway on a server within your network. 安装本地数据网关的服务器还必须安装 .NET Framework 4.6,才能使 MQ 连接器正常运行。The server where the on-premises data gateway is installed must also have .NET Framework 4.6 installed for the MQ connector to work.

    安装完网关以后,还必须在 Azure 中为本地数据网关创建资源。After you finish installing the gateway, you must also create a resource in Azure for the on-premises data gateway. 有关详细信息,请参阅设置数据网关连接For more information, see Set up the data gateway connection.

    如果 MQ 服务器公开可用,或在 Azure 中可用,则不必使用数据网关。If your MQ server is publicly available or available within Azure, you don't have to use the data gateway.

  • 要在其中添加 MQ 操作的逻辑应用。The logic app where you want to add the MQ action. 此逻辑应用必须使用与本地数据网关连接相同的位置,并且必须已经有一个用于启动工作流的触发器。This logic app must use the same location as your on-premises data gateway connection and must already have a trigger that starts your workflow.

    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.

创建 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 服务器名称,或输入后跟冒号和端口号的 IP 地址。For Server, you can enter the MQ server name, or enter the IP address followed by a colon and the port number.

    • 若要使用安全套接字层 (SSL),请选择“启用 SSL?”。To use 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 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 服务器需要你定义要用于 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.
    “MessageId”、“CorrelationId”、“GroupId”和其他属性MessageId, CorrelationId, GroupId, and other properties 根据不同的 MQ 消息属性找到对应的消息Browse for a message that's based on the different MQ message properties
    IncludeInfoIncludeInfo 若要在输出中包括其他消息信息,请选择“true”。To include additional message information in the output, select true. 若要在输出中省略其他消息信息,请选择“false”。To 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”,请选择有效的消息类型:“数据报”、“答复” 或“请求”For 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 about actions and limits, which are described by the connector's Swagger description, review the connector's reference page.

后续步骤Next steps