【发布时间】:2019-04-17 19:49:55
【问题描述】:
我希望下面的代码从 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
)
函数.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”(原因=“在“预处理”中检测到新队列消息。”,ID=f27fd7d1-1ace-****-****- 00fb021c9ca4)p>
[4/17/2019 5:54:39 PM] 触发器详细信息:MessageId:d28f96c5-****-****-9191-93f96a4423de,DequeueCount:1,InsertionTime:4/17/2019 5:下午 54:35 +00:00
[2019 年 4 月 17 日下午 5:54:39] 信息:收到 FunctionInvocationRequest,请求 ID:5bf59a45-****-****-9705-173d9635ca94,函数 ID:fa626dc9-****- ****-a59b-6a48f08d87e1,调用 ID:f27fd7d1-1ace-****-****-00fb021c9ca4
[4/17/2019 5:54:39 PM] Python 队列触发函数处理了一个队列项:name2
[2019 年 4 月 17 日下午 5:54:39] 信息:已成功处理 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)
INFO:已成功处理
– 让我认为这有效,我应该在队列中看到一条消息,但它是空白的。
为什么我没有看到队列中的消息?
谢谢
【问题讨论】:
标签: python-3.x azure azure-functions azure-queues