简体   繁体   中英

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. 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

{
  "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"
  }
}

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] 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] 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] Python queue trigger function processed a queue item: 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] Executed 'Functions.QueueTrigger' (Succeeded, 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM