Azure 服务总线 2.0 版本触发器在服务器中不起作用

Azure Service bus 2.0 version trigger is not working in server

我创建了一个用于向 Azure 服务总线主题发送消息的控制台,并创建了一个服务总线主题触发器。在本地它工作正常,但在 azure 中部署相同的功能后,相同的代码不起作用。我是 Azure 的新手,请帮助解决问题并在下面获取我的代码详细信息。

host.json

{
  "version": "2.0",
  "aggregator": {
    "batchSize": 1000,
    "flushTimeout": "00:00:30"
  },
  "extensions": {
    "cosmosDb": {},
    "durableTask": {},
    "eventHubs": {},
    "http": {},
    "queues": {},
    "sendGrid": {},
    "serviceBus": {}
  },
  "functions": [],
  "functionTimeout": "00:05:00",
  "healthMonitor": {
    "enabled": true,
    "healthCheckInterval": "00:00:10",
    "healthCheckWindow": "00:02:00",
    "healthCheckThreshold": 6,
    "counterThreshold": 0.80
  },
  "logging": {
    "fileLoggingMode": "debugOnly",
    "logLevel": {
      "Function.MyFunction": "Information",
      "default": "None"
    },
    "applicationInsights": {
      "samplingSettings": {
        "isEnabled": true,
        "maxTelemetryItemsPerSecond": 5
      }
    }
  },
  "singleton": {
    "lockPeriod": "00:00:15",
    "listenerLockPeriod": "00:01:00",
    "listenerLockRecoveryPollingInterval": "00:01:00",
    "lockAcquisitionTimeout": "00:01:00",
    "lockAcquisitionPollingInterval": "00:00:03"
  },
  "watchDirectories": [ "Shared", "Test" ]
}

local.setting.json

{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "DefaultEndpointsProtocol=https;....",
    "FUNCTIONS_WORKER_RUNTIME": "dotnet",
    "MyConnection": "Endpoint=sb://...."
  }
}

又试了一个

{
  "IsEncrypted": false,
  "Values": {
    "FUNCTIONS_WORKER_RUNTIME": "dotnet",
    "MyConnection": "Endpoint=sb://",
    "AzureWebJobsStorage": "UseDevelopmentStorage=true",
    "AzureWebJobsDashboard": "UseDevelopmentStorage=true"
  },
  "Host": {
    "LocalHttpPort": 7077
  }
}

函数代码:

 [FunctionName("Function1")]
    public static void Run([ServiceBusTrigger("*****", "*****", Connection = "MyConnection")]string mySbMsg, ILogger log)
    {
        log.LogInformation($"C# ServiceBus topic trigger function processed message: {mySbMsg}");
    }

MyConnection--> 在此处传递服务总线连接字符串。

在本地我们可以获得调试点,如果我们在另一台服务器上单独尝试 运行 相同的功能,它不会监听请求。我哪里做错了?帮我解决这个问题!

更新 此外,在发布 Azure 总线时单击 visual studio 中的应用程序设置。然后您还需要将连接字符串提供给远程。那么一定会成功的!

确保您已将 MyConnection 放入 Azure 门户的应用程序设置(平台功能> 应用程序设置> 应用程序设置部分),local.settings.json 未发布到 Azure。

并且我建议删除 host.json 中 "version": "2.0" 以外的其他设置。内容是示例host.json的结构说明,我们不需要全部,只需指定您需要的即可。

您的 local.settings.json 文件将包含这 3 个值(加上其他值)...

"SvcBusConStr": "Endpoint=sb://myservicebus Con String",
"SvcBusTopicName": "my-topic-name",
"SvcBusSubscriptionName": "my-sub-name",

Azure 中的应用程序配置屏幕页面需要这 3 个条目

SvcBusConStr  Endpoint=sb://myservicebus Con String
SvcBusTopicName   my-topic-name
SvcBusSubscriptionName   my-sub-name

注意前两个参数上的百分号以读取应用程序环境设置。我还添加了 explicit listen only right。

 [FunctionName("Function1")]
    public static void Run([ServiceBusTrigger("%SvcBusTopicName%", "%SvcBusSubscriptionName%", AccessRights.Listen, Connection = "SvcBusConStr")]string mySbMsg, ILogger log)
    {
        log.LogInformation($"C# ServiceBus topic trigger function processed message: {mySbMsg}");
    }

我的回答可能无法完美涵盖 Azure Functions 2.0。