1

I am new to Azure. Forgive me if the question is basic. I have the following http trigger intended to stream messages to the Queue Storage.

import logging
import azure.functions as func
def main(req: func.HttpRequest, msg: func.Out[func.QueueMessage]) -> func.HttpResponse:
    logging.info('Python HTTP trigger function processed a request.')
    input_msg = req.params.get('message')
    logging.info(input_msg)
    msg.set(input_msg)

    return func.HttpResponse(status_code=200, body='GotIt')

Tested it Locally and; enter image description here

Deployed it and it runs ok as well enter image description here

However, when I check the queue it is empty;

enter image description here

Questions;

  1. Why is the queue empty and what can I do to ensure it registers messages?
  2. Is it not locking because my code is not writing messages?

Your help will be highly appreciated.

wwnde
  • 26,119
  • 6
  • 18
  • 32

1 Answers1

1

Update:

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": "msg",
      "queueName": "outqueue",
      "connection": "AzureStorageQueuesConnectionString"
    }
  ]
}

local.settings.json

{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "",
    "FUNCTIONS_WORKER_RUNTIME": "python",
    "AzureStorageQueuesConnectionString":"DefaultEndpointsProtocol=https;AccountName=0730bowmanwindow;AccountKey=xxxxxx;EndpointSuffix=core.windows.net"
  }
}

host.json

{
  "version": "2.0",
  "logging": {
    "applicationInsights": {
      "samplingSettings": {
        "isEnabled": true,
        "excludedTypes": "Request"
      }
    }
  },
  "extensionBundle": {
    "id": "Microsoft.Azure.Functions.ExtensionBundle",
    "version": "[1.*, 1.2.0)"
  }
}

Original Answer:

I have do a simple test. Below code works fine on my side, you can have a try:

import logging

import azure.functions as func


def main(req: func.HttpRequest,msg: func.Out[str]) -> func.HttpResponse:
    logging.info('Python HTTP trigger function processed a request.')
    input_msg = req.params.get('message')
    logging.info(input_msg)
    msg.set(input_msg)
    return func.HttpResponse(
            "This is a test.",
            status_code=200
    )

This is the doc:

https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-storage-queue-output?tabs=python#example

Send:

enter image description here

Queue Storage:

enter image description here

enter image description here

Cindy Pau
  • 13,085
  • 1
  • 15
  • 27
  • I will try and revert – wwnde Nov 13 '20 at 07:19
  • still nothing gets written – wwnde Nov 13 '20 at 07:24
  • @wwnde I test the same code of you. I works with no problem. So it should have no problem with your code. Any limit of your storage account? You can also have a check of the configuration settings I updated. – Cindy Pau Nov 13 '20 at 07:28
  • are there queue settings that maybe I need to check? – wwnde Nov 13 '20 at 07:30
  • @wwnde If you use connection string you should have totally access to queue. Can you show the structure of your AzureStorageQueuesConnectionString?(No need to show the account key and account) – Cindy Pau Nov 13 '20 at 07:33
  • `{ "IsEncrypted": false, "Values": { "AzureWebJobsStorage": "", "FUNCTIONS_WORKER_RUNTIME": "python", "AzureStorageQueuesConnectionString":"DefaultEndpointsProtocol=https;AccountName=fffff;AccountKey=dddddd;EndpointSuffix=core.windows.net" } }` – wwnde Nov 13 '20 at 07:35
  • @wwnde Any service read this queue? Maybe try to write to another queue instead of outqueue. Your code and connection string is no problem. – Cindy Pau Nov 13 '20 at 07:40
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/224508/discussion-between-wwnde-and-bowman-zhu). – wwnde Nov 13 '20 at 07:42
  • Hi @Bowman Zhu, a quick one. it works well on local but once deployed, when I run using the azure url it doesnt work. Are you able to help? I am happy to post another question if you need me to. Please.. – wwnde Nov 16 '20 at 02:28
  • @wwnde Ok, yes you can post another question. I will do a test. Please show the details.:) – Cindy Pau Nov 16 '20 at 02:29
  • When I go to the function, configuration and copy the url `https://harvestlayerqueuestorage.azurewebsites.net/api/CentroidsUpdateTrigger?message=11111` nothing is logged to the queue while `https://harvestlayerqueuestorage.azurewebsites.net/api/CentroidsUpdateTrigger?message=11111` does. What could be reason? – wwnde Nov 16 '20 at 02:31
  • Do you set the configuration settings of the connection string? On local it is in local.settings.json. But on portal azure function app don't get environment variable from local.settings.json. This is the screenshot: https://i.stack.imgur.com/u43Yn.png It is the same with the Values section of local.settings.json. – Cindy Pau Nov 16 '20 at 02:32
  • @wwnde I am sorry, i forget to @ you. You can have a look of my above comment. – Cindy Pau Nov 16 '20 at 02:38
  • Let me check and revert – wwnde Nov 16 '20 at 02:40
  • What do I add in the Name, value? sorry, I am so green in azure – wwnde Nov 16 '20 at 02:43
  • @wwnde May be we can go to the chat room. – Cindy Pau Nov 16 '20 at 02:45
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/224608/discussion-between-bowman-zhu-and-wwnde). – Cindy Pau Nov 16 '20 at 02:45
  • are you able to help? https://stackoverflow.com/questions/65677939/how-can-i-create-a-python-webhook-sender-app – wwnde Jan 12 '21 at 04:16