Azure HTTPtrigger函数未写入Azure存储队列

问题描述 投票:0回答:1

我期望下面的代码从func.HttpRequest获取JSON主体,将该消息写入Azure存储队列,然后将成功消息返回给调用者。除了我的存储队列是空白之外,这是有效的。

import logging

import azure.functions as func


def main(req: func.HttpRequest,
         orders: func.Out[func.QueueMessage]) -> func.HttpResponse:


    logging.info('Python HTTP trigger function processed a request.')
    message = req.get_json()
    logging.info(message)
    orders.set(message)
    return func.HttpResponse(
        body=”success”,
        status_code=200
    )

Function.json

{
  "scriptFile": "__init__.py",
  "bindings": [
    {
      "authLevel": "anonymous",
      "type": "httpTrigger",
      "direction": "in",
      "name": "req",
      "methods": [
        "get",
        "post"
      ]
    },
    {
      "type": "http",
      "direction": "out",
      "name": "$return"
    },
  {
    "type": "queue",
    "direction": "out",
    "name": "orders",
    "queueName": "preprocess",
    "connection": "orders_STORAGE"
  }
  ]
}

Local.settings.json

{
  "IsEncrypted": false,
  "Values": {
    "FUNCTIONS_ER_RUNTIME": "python",
    "AzureWebJobsStorage": "AzureWebJobsStorage",
    "orders_STORAGE": "DefaultEndpointsProtocol=https;AccountName=orders;AccountKey=*****;EndpointSuffix=core.windows.net"
  }
}

终端输出:

... [4/17/2019 5:54:39 PM]执行'Functions.QueueTrigger'(Reason ='在'preprocess'上检测到新队列消息。',Id = f27fd7d1-1ace - **** - **** -00fb021c9ca4)

[4/17/2019 5:54:39 PM]触发详情:MessageId:d28f96c5 - **** - **** - 9191-93f96a4423de,DequeueCount:1,InsertionTime:4/17/2019 5:54:35 PM +00:00

[4/17/2019 5:54:39 PM]信息:收到FunctionInvocationRequest,请求ID:5bf59a45 - **** - **** - 9705-173d9635ca94,功能ID:fa626dc9 - **** - *** * -a59b-6a48f08d87e1,调用ID:f27fd7d1-1ace - **** - **** - 00fb021c9ca4

[4/17/2019 5:54:39 PM] Python队列触发器函数处理了一个队列项:name2

[4/17/2019 5:54:39 PM]信息:已成功处理FunctionInvocationRequest,请求ID:5bf59a45 - **** - **** - 9705-173d9635ca94,功能ID:fa626dc9-3313 - **** - **** 6a48f08d87e1,调用ID:f27fd7d1-1ace - **** - **** - 00fb021c9ca4

[4/17/2019 5:54:39 PM]执行'Functions.QueueTrigger'(成功,Id = f27fd7d1-1ace - **** - **** - 00fb021c9ca4)

信息:已成功处理

- 让我觉得这很有效,我应该在队列中看到一条消息,但它是空白的。

为什么我没有看到队列中的消息?

谢谢

python-3.x azure azure-functions azure-queues
1个回答
0
投票

您的终端输出显示QueueTrigger检测到新消息preprocess,所以实际上它已写入。

至于队列中没有消息,因为它已处理到您的函数。邮件传递后,它将从队列中删除。这就是你的队列空白的原因。

从教程:Test the function,您还可以找到描述:

回到Storage Explorer,单击Refresh并验证消息是否已处理并且不再在队列中。

© www.soinside.com 2019 - 2024. All rights reserved.