【发布时间】:2020-08-12 15:33:39
【问题描述】:
我们知道事件中心的连接字符串可以从 local.setting.json 文件中使用。所以对于不同环境下的同一个函数应用,我可以在天蓝色门户的应用设置中添加事件中心连接字符串设置。
由于 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
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "dotnet",
"EventHubConnectionAppSetting": "Endpoint=.....",
"EventHubConsumerGroup": "myconsumergroup"
}
}
【问题讨论】:
标签: c#-4.0 azure-functions azure-eventhub azure-function-app