Put/Post JSON 通过逻辑应用程序向 Azure 存储队列发送消息

Put/Post JSON message to Azure Storage Queue via Logic App

我希望能够将逻辑应用程序用于 Azure 存储队列中的 put/post 消息,因为我想利用 HTTP 的托管标识选项逻辑应用程序提供。

我有一个逻辑应用程序,它使用 HTTP 操作将 post XML 消息发送到队列,我有一个 "Put a message on a queue" 操作将 JSON 消息发送到队列用于调试目的。

我的最终目标是能够使用带有托管标识的 HTTP 操作作为身份验证,但能够像 "Put a message on a queue" 操作一样将 post JSON 消息发送到队列到.

您当然可以将 JSON 作为邮件正文发送。事实上,您可以发送任何文本。您只需确保作为消息正文发送的文本必须 XML 安全,例如将 < 替换为 &lt; 等。通常会发送 Base64 编码的字符串消息以确保这一点。

来自REST API documentation

A message must be in a format that can be included in an XML request with UTF-8 encoding. To include markup in the message, the contents of the message must either be XML-escaped or Base64-encode. Any XML markup in the message that is not escaped or encoded will be removed before the message is added to the queue.

以下是对我有用的方法:

  1. 在逻辑应用程序上启用“托管身份”。

  2. 已添加 Storage-Queue-Contributor 存储权限 queue。

  3. 使用 utcnow('R') 获取此日期格式(“星期二,2020 年 9 月 8 日 12:03:08 GMT”) 对于 x-ms-date HTTP header(MS 没有关于此的文档)。

  4. 里面插入了JSON数据

    <QueueMessage> 
        <MessageText>
        {
          "car": "Audi",
          "year": 1983
        }
       </MessageText>  
    </QueueMessage>
    

逻辑应用程序设计器的最终结果: