Search code examples
python-3.xazure-functionsazure-http-trigger

Http Trigger-Python-Log Specific Message Constantly and not URL body or payload


Building on an earlier question. The following code is an httptrigger that listed to a gis layer edits and updates. It logs into the queue the url payload. I do not want the payload loaded but a specific repetitive message so that it is overwritten everytime for I do not want to dequeue every now and then. How can I go about this?

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(req.get_body())
    return func.HttpResponse(
            "This is a test.",
            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": "msg",
  "queueName": "outqueue1",
  "connection": "AzureStorageQueuesConnectionString"
  }
  ]
  }

Solution

  • I do not want the payload loaded but a specific repetitive message so that it is overwritten everytime for I do not want to dequeue every now and then.

    No, when you put in the same message, It will not overwritten. It just queued in the queue storage.

    If you want to process the message in queue, just use queueclient or use queuetrigger of azure function.(queuetrigger of function is based on queueclient, they are basically same.)

    This is the API reference of queue:

    https://learn.microsoft.com/en-us/python/api/azure-storage-queue/azure.storage.queue?view=azure-python

    You can use it to process message in the queue with python code.

    And this is the queuetrigger of azure function:(This is already integrated and can be used directly)

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