如何计算Azure EventHub中的消费者延迟

huangapple go评论57阅读模式
英文:

How to calculate consumer lag in Azure EventHub

问题

我有一个C# .NET 7应用程序,我在其中一侧将事件发布到Azure EventHub,并在另一侧使用Azure Function和EventHubTrigger属性来消费它。

我正在使用以下包:

  • Azure.Messaging.EventHubs 5.7.5
  • Microsoft.Azure.Functions.Worker.Extensions.EventHubs 5.1.0

我想要做的是计算接收事件在流中的位置与当前使用的消费者组的最后序列号之间的差距。

如何获取这两个信息?

我尝试使用BlobCheckpointStore来检索我的消费者组中每个分区的LastEnqueuedSequenceNumber,但与Azure存储中的关联文件保持为空白。而对于接收到的事件,我不知道如何获取其位置。

英文:

I have a C# .net 7 application where I publish events to an Azure EventHub on one side, and consume it on the other side using an Azure Function with the EventHubTrigger attribute.
I am using the following packages:

  • Azure.Messaging.EventHubs 5.7.5
  • Microsoft.Azure.Functions.Worker.Extensions.EventHubs 5.1.0
[Function("HandleEventHubMessage")]
public async Task Run(
    [EventHubTrigger("<my-eventhub>", Connection = "<MyEventHubConnection>", ConsumerGroup = "<my-consumer-group>")] string[] messages, 
    FunctionContext context)
{
    ...
}

What I would like to do is to calculate the consumer lag between the received event position in the stream and the last sequence number for the current consumer group.

How can I retrieve these two information?

I tried using the BlobCheckpointStore to retrieve the LastEnqueuedSequenceNumber on each partition for my consumer group, but associated files in the azure storage stays empty. And for the received event, I have no clue on how to retrieve its position.

答案1

得分: 2

请看,Azure Monitor提供了适用于高级SKU及以上的诊断功能,用于检查消费者滞后,参见此文档

但你还可以使用此API来以编程方式计算滞后,然后将你正在处理的特定分区的当前事件序列与最后一个入队的事件进行比较。

另一种选择是使用PartitionProperties类,它也可以按分区来提供最后一个入队的序列。

英文:

Notice that there is an Azure Monitor diagnostic available for Premium SKU and above that checks for consumer lag, see this doc

But you can also calculate the lag programmatically by using this api, then you compare the current event sequence that you are processing for a particular partition with the last enqueued one.

One more alternative is to use the PartitionProperties class which can also give you the last enqueued sequence on a per partition basis.

huangapple
  • 本文由 发表于 2023年3月7日 22:25:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/75663239.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定