[英]Azure HTTPtrigger function not writing to Azure Storage Queue
I am expecting the below code to take a JSON body from func.HttpRequest
, write that message to an Azure Storage Queue and then return a success message to the caller. 我期望以下代码从
func.HttpRequest
获取JSON主体,将该消息写入Azure存储队列,然后将成功消息返回给调用者。 This works except that my Storage Queue is blank. 除了我的存储队列是空白之外,这是有效的。
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 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 Local.settings.json
{
"IsEncrypted": false,
"Values": {
"FUNCTIONS_ER_RUNTIME": "python",
"AzureWebJobsStorage": "AzureWebJobsStorage",
"orders_STORAGE": "DefaultEndpointsProtocol=https;AccountName=orders;AccountKey=*****;EndpointSuffix=core.windows.net"
}
}
Terminal output: 终端输出:
… [4/17/2019 5:54:39 PM] Executing 'Functions.QueueTrigger' (Reason='New queue message detected on 'preprocess'.', Id=f27fd7d1-1ace-****-****-00fb021c9ca4) ... [4/17/2019 5:54:39 PM]执行'Functions.QueueTrigger'(Reason ='在'preprocess'上检测到新队列消息。',Id = f27fd7d1-1ace - **** - **** -00fb021c9ca4)
[4/17/2019 5:54:39 PM] Trigger Details: MessageId: d28f96c5-****-****-9191-93f96a4423de, DequeueCount: 1, InsertionTime: 4/17/2019 5:54:35 PM +00:00 [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] INFO: Received FunctionInvocationRequest, request ID: 5bf59a45-****-****-9705-173d9635ca94, function ID: fa626dc9-****-****-a59b-6a48f08d87e1, invocation ID: f27fd7d1-1ace-****-****-00fb021c9ca4 [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 queue trigger function processed a queue item: name2 [4/17/2019 5:54:39 PM] Python队列触发器函数处理了一个队列项:name2
[4/17/2019 5:54:39 PM] INFO: Successfully processed FunctionInvocationRequest, request ID: 5bf59a45-****-****-9705-173d9635ca94, function ID: fa626dc9-3313-****-****6a48f08d87e1, invocation ID: f27fd7d1-1ace-****-****-00fb021c9ca4 [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] Executed 'Functions.QueueTrigger' (Succeeded, Id=f27fd7d1-1ace-****-****-00fb021c9ca4) [4/17/2019 5:54:39 PM]执行'Functions.QueueTrigger'(成功,Id = f27fd7d1-1ace - **** - **** - 00fb021c9ca4)
INFO: Successfully processed
信息:已成功处理
– makes me think this worked and I should see a message in my queue, but it is blank. - 让我觉得这很有效,我应该在队列中看到一条消息,但它是空白的。
Why am I not seeing the message in the queue? 为什么我没有看到队列中的消息?
Thanks 谢谢
Your Terminal output shows the QueueTrigger detected the new message preprocess
, so actually it has been write in. 您的终端输出显示QueueTrigger检测到新消息
preprocess
,因此实际上它已写入。
As for no message in your queue, because it's processed to your function. 至于队列中没有消息,因为它已处理到您的函数。 After a message is delivered it will be removed from the queue.
邮件传递后,它将从队列中删除。 That's why your queue is blank.
这就是你的队列空白的原因。
And from the tutorial: Test the function , you could also find the description : 从教程: 测试函数 ,您还可以找到描述:
Back in Storage Explorer, click Refresh and verify that the message has been processed and is no longer in the queue.
回到Storage Explorer,单击Refresh并验证消息是否已处理并且不再在队列中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.