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

标签 c# azure azure-functions azureservicebus azure-servicebus-topics

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

主机.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" ]
}

本地.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结构的示例,我们不需要全部,只需指定您需要的即可。

关于c# - Azure 服务总线 2.0 版本触发器在服务器中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53595487/

相关文章:

node.js - Node-Powershell Azure 函数应用程序不会读取命令

python - 将 Excel 文件流保存到 azure blob 存储

c# - 当 DateTime 字段为 null 时 LINQ 中的 "Specified cast is not valid"

c# - 尝试激活图形 API 时无法解析类型 'Microsoft.Identity.Web.ITokenAcquisition' 的服务

使用 ANTLR 3 的 C# 语法

查询 Azure 时的 Powershell 过滤/格式化

azure - 更改 Azure 中从 Visual Studio 发布的 Azure Function 的计时器间隔

python - 如何解决python中的azure devop api对象移动结果

c# - 如何在 C# 中获取子列表

c# - 事件参数——它们应该反射(reflect)事件发生时的状态快照还是实时数据?