1

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"
  }
  ]
  }
wwnde
  • 26,119
  • 6
  • 18
  • 32
  • I am not sure about your question. What does you mean about `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.`? – Cindy Pau Nov 16 '20 at 07:26
  • Maybe you can describe a simple usage scenario? – Cindy Pau Nov 16 '20 at 07:27
  • @Bowman Zhu , I need every time something happens on the client url, a message `Edits have been done` should be written onto the queue. Currently I get a specific json from the url logged. ` – wwnde Nov 16 '20 at 07:32

1 Answers1

1

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

Cindy Pau
  • 13,085
  • 1
  • 15
  • 27
  • little question mate – wwnde Nov 18 '20 at 01:13
  • you have got a minute? – wwnde Nov 19 '20 at 03:00
  • stack on a function . A minute to help – wwnde Mar 31 '21 at 07:43
  • @wwnde ok, what question?:) – Cindy Pau Mar 31 '21 at 07:45
  • I have an old function that was writing to blob. Writing was not embedded in the function head. I instead was `from azure.storage.blob import BlockBlobService` and writing code within function to write to blob via `BlockBlobService`. This has failed. I have decide to write a httptrigger that outputs blob and have issues with bindings – wwnde Mar 31 '21 at 07:50
  • @wwnde Why BlockBlobService failed, I did this before and it seems no problem, any error you get? – Cindy Pau Mar 31 '21 at 07:54
  • Restarted, send it through soon – wwnde Mar 31 '21 at 07:58
  • `Result: Failure Exception: ModuleNotFoundError: No module named 'azure.storage'. Troubleshooting Guide: https://aka.ms/functions-modulenotfound` where in requirement.txt I have `azure-functions azure-identity azure-storage-blob arcgis` – wwnde Mar 31 '21 at 08:07
  • @wwnde The requirement.txt determines the installation of modules in the virtual environment. Is your function app running in a global environment or in a virtual environment? – Cindy Pau Mar 31 '21 at 08:15
  • local at the moment – wwnde Mar 31 '21 at 08:15
  • @wwnde When a function app is running locally, there are two situations: running in a global environment and running in a virtual environment. You need to check this: https://i.stack.imgur.com/NIZDx.png – Cindy Pau Mar 31 '21 at 08:18
  • @wwnde There is no prefix in front of the drive letter in the global environment, but it is necessary to ensure that there is a prefix in front of the drive letter when running in a virtual environment. I suspect that your function app didn't not activate the virtual environment, because the requirements.txt is designed for the virtual environment. – Cindy Pau Mar 31 '21 at 08:21
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/230580/discussion-between-wwnde-and-bowman-zhu). – wwnde Mar 31 '21 at 08:25