使用非默认使用者组时不会触发事件中心触发器 Azure 函数

Event Hub Trigger Azure Function Not Being Triggered When Using Non-Default Consumer Group

所以我有一个基本设置来侦听进入事件中心的事件,使用事件中心触发器函数,定义如下:

[FunctionName("myfunction")]
public async Run([EventHubTrigger(myeventhub, Connection = "EventHubConnectionAppSetting", ConsumerGroup = %myconsumergroup%)], EventData eventHubMessage, ILogger logger)

connection 和 consumergroup 参数的值在我的本地设置中。

运行 我的功能和通过 Postman 发送事件(正确验证),该功能未被触发。

每次触发函数的唯一方法是从参数中删除 ConsumerGroup,这将导致它指向事件中心的 $Default 使用者组:

[FunctionName("myfunction")]
public async Run([EventHubTrigger(myeventhub, Connection = "EventHubConnectionAppSetting"], EventData eventHubMessage, ILogger logger)

我的目标是保留我的自定义消费者组,并为进入该消费者组的事件触发函数。

我会提到我正在本地测试并使用本地存储:

AzureWebJobsStorage="UseDevelopmentStorage=true"

但显然,所讨论的事件中心是 Azure 上实际创建的资源,其下也存在相关的使用者组。

可以直接在函数中使用消费组名,如下:

[FunctionName("myfunction")]
public async Run([EventHubTrigger(myeventhub, Connection = "EventHubConnectionAppSetting", ConsumerGroup = "myconsumergroup_name")], EventData eventHubMessage, ILogger logger)

如果要使用此模式%myconsumergroup%,可参考以下步骤:

在local.settings.json中(记得右击文件 -> select 属性 -> 将“复制到输出目录”设置为“如果更新则复制”),定义键值如下:

{
    "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "UseDevelopmentStorage=true",
    "FUNCTIONS_WORKER_RUNTIME": "dotnet",
    "EventHubConnectionAppSetting": "xxxx",
    "EventHubConsumerGroup": "your_consumergroup_name"
  }
}

然后在函数方法中,定义如下函数:

    [FunctionName("Function1")]
    public static async Task Run([EventHubTrigger("eventhub_name", Connection = "EventHubConnectionAppSetting",ConsumerGroup = "%EventHubConsumerGroup%")] EventData[] events, ILogger log)

注意:我使用最新的功能包。