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

C# 4.0 EventHubTrigger函数应用程序,将事件中心名称和使用者组名称动态传递给事件中心属性,c#-4.0,azure-functions,azure-eventhub,azure-function-app,C# 4.0,Azure Functions,Azure Eventhub,Azure Function App,我们知道可以从local.setting.json文件使用事件中心的连接字符串。因此,对于不同环境中的相同功能应用程序,我可以在azure门户的应用程序设置中添加事件中心连接字符串设置 由于EventHubTrigger函数应用程序还需要事件名称和消费者组(可选)作为属性参数,我想知道如何从应用程序设置中使用事件中心名称和消费者组 public static void EventHubTriggerFunc([EventHubTrigger("myeventhubname", Connect

我们知道可以从local.setting.json文件使用事件中心的连接字符串。因此,对于不同环境中的相同功能应用程序,我可以在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
 }
local.settings.Json


尝试了@Roman Kiss answer,并将其应用于Python Azure函数,效果良好

function.json
中:

{
  "scriptFile": "__init__.py",
  "bindings": [
    {
      "type": "eventHubTrigger",
      "name": "events",
      "direction": "in",
      "eventHubName": "%EVENT_HUB_NAME%",
      "connection": "EVENT_HUB_CONN_STR",
      "cardinality": "many",
      "consumerGroup": "$Default",
      "dataType": "binary"
    }
  ]
}
{
  ...
  "Values": {
    ...
    "EVENT_HUB_NAME": "<actual name of event hub>",
    "EVENT_HUB_CONN_STR": "Endpoint=sb://...;SharedAccessKeyName=...;SharedAccessKey=...",
    ...
  },
}
请注意,连接字符串不需要
%

local.settings.json
中:

{
  "scriptFile": "__init__.py",
  "bindings": [
    {
      "type": "eventHubTrigger",
      "name": "events",
      "direction": "in",
      "eventHubName": "%EVENT_HUB_NAME%",
      "connection": "EVENT_HUB_CONN_STR",
      "cardinality": "many",
      "consumerGroup": "$Default",
      "dataType": "binary"
    }
  ]
}
{
  ...
  "Values": {
    ...
    "EVENT_HUB_NAME": "<actual name of event hub>",
    "EVENT_HUB_CONN_STR": "Endpoint=sb://...;SharedAccessKeyName=...;SharedAccessKey=...",
    ...
  },
}
{
...
“价值观”:{
...
“事件中心名称”:“”,
“EVENT_HUB_CONN_STR”:“Endpoint=sb://……;SharedAccessKeyName=…;SharedAccessKey=…”,
...
},
}

感谢上帝给了我这个答案!哦,也谢谢你!;)太酷了,谢谢!我只想添加名为Azure函数绑定表达式模式,并添加到源代码的链接: