python-3.x - 服务总线未在 Azure 上触发,在本地工作

标签 python-3.x azure azure-functions azureservicebus

当我使用 Azure 服务总线队列作为触发器托管在 Azure 上时,无法触发我的 Azure 函数。它在本地运行时工作正常,但在远程运行时则不然。

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

主机.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())

文件夹结构

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

以及我在 Azure 上的应用程序设置 enter image description here

我的开发环境如下:

1) Windows 10 专业版 2)VS代码1.41.1 3) Azure Functions CLI 2.7.1948 4)Python 3.7.4

最佳答案

您的配置问题是:

"autoComplete": false,

autocomplete=false is only supported for C# ,所以在 Python 中,不可能以交互方式发送死信消息。

换句话说,这意味着使消息成为死信的唯一方法是在处理消息时引发异常。

关于python-3.x - 服务总线未在 Azure 上触发,在本地工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59650465/

相关文章:

azure - #load 无法加载共享 .fsx

python - 应用于可迭代对象的每个元素的 bool 语句分支

azure - 如何将 Azure API 管理开发人员门户更改从一个实例发布到另一实例?

python - VS Code Azure 部署 Python Http 触发器功能失败 - 找不到 GLIB_2.27

node.js - 如何在 Azure Function App 中禁用自适应采样

azure - "The binding type(s) ' queueTrigger ' are not registered"错误随机出现。

python - 带有 Python 3.3 的蓝牙服务器

python - Brew 升级 python 返回 "python not installed"

python - pygal:多系列饼图上的标签

json - Invoke-Webrequest 不正确的 Json 格式 "Cannot bind parameter ' headers' "