Azure Function v4 .net6 事件中心触发器 - 如何获取 EnqueuedTimeUTC?

问题描述 投票:0回答:0

我有一个可用的 Azure Functions 应用程序,带有一个事件中心触发器。 它使用 Microsoft.Azure.Functions.Worker 1.10、函数运行时 4、.Net 6 并作为独立运行(非进程内)。

当前函数签名如下所示:

    Function("MyFunction")]
        public async Task Run([EventHubTrigger("my-eventhub",
            ConsumerGroup = "a-consumer-group",
            Connection = "EventHub.ConnectionString")] string[] messages)
        {
         //Do stuff
        }

我想扩展它以获取排队时间(事件在事件中心结束的时间)。

所以,我意识到在 Functions runtime v4 中,我不能像在旧版本中那样获取 EventData[],相反我应该使用 BindingContext。

所以我试过这个:

    Function("MyFunction")]
        public async Task Run([EventHubTrigger("my-eventhub",
            ConsumerGroup = "a-consumer-group",
            Connection = "EventHub.ConnectionString")] string[] messages, FunctionContext context)
        {
            var data = context.BindingContext.BindingData["enqueuedTimeUtcArray"];
        
            //data would always be empty
        }

发现这是错误的方法,并看到更多的例子分解字段,我尝试了以下方法:

    Function("MyFunction")]
        public async Task Run([EventHubTrigger("my-eventhub",
            ConsumerGroup = "a-consumer-group",
            Connection = "EventHub.ConnectionString")] string[] messages,
            DateTime[] enqueuedTimeUtcArray,
            long[] sequenceNumberArray,
            string[] offsetArray,
            Dictionary<string, JsonElement>[] propertiesArray,
            Dictionary<string, JsonElement>[] systemPropertiesArray))
        {
            var data = enqueuedTimeUtcArray;
        
            //data would always be empty
    }

我尝试了这些主题的各种变体,包括参考以下内容: https://github.com/Azure/azure-functions-dotnet-worker/pull/508/commits/590e69b9f9fad14730daf0226fce2b93c9acb289 https://github.com/Azure/azure-functions-dotnet-worker/wiki/.NET-Worker-bindings#using-method-attributes-works-if-you-only-have-one-output-binding https://github.com/Azure/azure-functions-dotnet-worker/issues/283 https://dev.to/kenakamu/azure-function-and-net-5-how-to-get-eventdata-for-event-hub-input-binding-3bmm

函数仍然触发,它提供的功能(替换为//do stuff)仍然顺利运行,但仍然没有 EnqueueTimes ...我做错了什么?

azure azure-functions azure-eventhub
© www.soinside.com 2019 - 2024. All rights reserved.