2
votes

I am unable to get my Azure Function to trigger when hosted on azure, using azure service bus queues as a trigger. It works fine when its run locally, but doesn't remotely.

function.json

{
  "scriptFile": "__init__.py",
  "bindings": [
    {
      "name": "msg",
      "type": "serviceBusTrigger",
      "direction": "in",
      "AzureWebJobsStorage": "AzureWebJobsStorage",
      "queueName": "selectivitycalculation",
      "connection":  "AzureServiceBusConnectionString"
    }
  ]
}

local.settings.json

{
  "IsEncrypted": false,
  "Values": {
    "FUNCTIONS_WORKER_RUNTIME": "python",
    "AzureWebJobsStorage": XXXXXX,
    "AzureServiceBusConnectionString": XXXXXXX
  }
}

host.json

{
    "version": "2.0",
    "extensions": {
        "serviceBus": {
            "prefetchCount": 100,
            "messageHandlerOptions": {
                    "autoComplete": false,
                    "maxConcurrentCalls": 32,
                    "maxAutoRenewDuration": "00:55:00"
            }
        }
    },
    "extensionBundle": {
        "id": "Microsoft.Azure.Functions.ExtensionBundle",
        "version": "[1.*, 2.0.0)"
    },
    "functions": [ "SelectivityCalculation" ],
    "logging": {
        "fileLoggingMode": "debugOnly",
        "logLevel": {
          "Function.MyFunction": "Information",
          "default": "None"
        },
        "applicationInsights": {
            "samplingSettings": {
              "isEnabled": true,
              "maxTelemetryItemsPerSecond" : 20
            }
        }
    }
}

__init__.py

import azure.functions as func
import logging
import sys
from .azure_functions_controller import selectivity_callback

def main(msg: func.ServiceBusMessage):
    logger.info('Python ServiceBus queue trigger processed message.')
    print('working')
    selectivity_callback(msg.get_body())

Folder Structure

Calculator
 | - __app__
 | | - SelectivityCalculation
 | | | - __init__.py
 | | | - azure_functions_controller.py
 | | | - functions.json
 | | - SharedCode
 | | | - ...
 | | - host.json
 | | - bin

And my application settings on Azure enter image description here

My dev environment is as follows:

1) Windows 10 Pro 2) VS Code 1.41.1 3) Azure Functions CLI 2.7.1948 4) Python 3.7.4

2
I have the same issue as I've added PrefetchCount to host.json.Marco

2 Answers

0
votes

Have you remember to upload Function Settings file to Azure?

At least you need these settings to make the Function run fine:

[
  {
    "name": "APPINSIGHTS_INSTRUMENTATIONKEY",
    "value": "xxxxxxxxxxxxxxxx",
    "slotSetting": false
  },
  {
    "name": "AzureWebJobsStorage",
    "value": "xxxxxxxxxxxxxxxx",
    "slotSetting": false
  },
  {
    "name": "bowmantest_SERVICEBUS",
    "value": "xxxxxxxxxxxxxxxx",
    "slotSetting": false
  },
  {
    "name": "BUILD_FLAGS",
    "value": "UseExpressBuild",
    "slotSetting": false
  },
  {
    "name": "ENABLE_ORYX_BUILD",
    "value": "true",
    "slotSetting": false
  },
  {
    "name": "FUNCTIONS_EXTENSION_VERSION",
    "value": "~2",
    "slotSetting": false
  },
  {
    "name": "FUNCTIONS_WORKER_RUNTIME",
    "value": "python",
    "slotSetting": false
  },
  {
    "name": "SCM_DO_BUILD_DURING_DEPLOYMENT",
    "value": "1",
    "slotSetting": false
  },
  {
    "name": "XDG_CACHE_HOME",
    "value": "/tmp/.cache",
    "slotSetting": false
  }
]

Given that you are working well locally, I suspect it is because you did not upload a configuration file. If my Application Settings only has three settings from your screenshot, then my Function will not display anything when it is triggered.

0
votes

The problem with your configuration is:

"autoComplete": false,

autocomplete=false is only supported for C#, so in Python it is not possible interactively send a message in dead-letter.

In other words, this means that the only way to dead letter a message is raise an exception while you're working on it.