EventHubTrigger函数应用程序,将事件中心名称和使用者组名称动态传递给事件中心属性

Viv*_*jan 0 c#-4.0 azure-eventhub azure-functions azure-function-app

我们知道可以从local.setting.json文件使用事件中心的Connection字符串。因此,对于不同环境中的同一功能应用程序,我可以在azure门户的“应用程序设置”中添加事件中心连接字符串设置。

由于EventHubTrigger函数应用程序还将事件名称和使用者组(可选)用作属性参数,我想知道如何从应用程序设置中使用事件中心名称和使用者组?

  public static void EventHubTriggerFunc([EventHubTrigger("myeventhubname", Connection = "EventHubConnectionAppSetting", ConsumerGroup = "myconsumergroupname")] EventData myEventHubMessage, DateTime enqueuedTimeUtc, Int64 sequenceNumber, string offset, ILogger log)
 {
   // Here EventHubConnectionAppSetting is specified in local.setting.json file
   //myeventhubname & myconsumergroupname are hard coded string
 }
Run Code Online (Sandbox Code Playgroud)

本地设置

   {
    "IsEncrypted": false,
   "Values": {
   "AzureWebJobsStorage": "UseDevelopmentStorage=true",
   "FUNCTIONS_WORKER_RUNTIME": "dotnet",
   "EventHubConnectionAppSetting": "Endpoint=.....",
   "EventHubConsumerGroup": "myconsumergroup"
  }
   }
Run Code Online (Sandbox Code Playgroud)

Rom*_*iss 5

([EventHubTrigger("%myeventhubname%", Connection = "EventHubConnectionAppSetting", ConsumerGroup = "%myconsumergroupname%")]
Run Code Online (Sandbox Code Playgroud)