Azure Function Event Hub一次触发一批

发布于 2025-01-12 04:08:39 字数 417 浏览 2 评论 0 原文

我正在开发一个通过事件中心获取更改通知的项目(https: //learn.microsoft.com/en-us/graph/change-notifications-delivery)。

我的Azure函数(事件接收器)批量接收事件。收到每个批次后,它会处理数据(做一些工作)。第二批更新第一批设置的值。

事件中心有 3 个分区。

当多个批次同时到达时就会出现问题。 。第二批在第一批更新值之前进入。

有没有办法一次只接收一批?

我不关心批次的顺序,但我想仅在处理第一个批次后才获取下一个批次触发器。

提前致谢。

I am working on a project which gets change notifications through Event Hubs(https://learn.microsoft.com/en-us/graph/change-notifications-delivery).

My Azure Function(Event Receiver) receives the events in batches. After receiving each batch, it processes the data (does a bit of work). The second batch updates the value set by the first batch.

The Event Hub has 3 partitions.

The problem arises when multiples batches arrives at the same time. . The second batch comes in before the first batch has updated the value.

Is there a way to receive only one batch at a time?

I am not bothered about the order of batches, but I want to get the next batch trigger only after the first batch is processed.

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

忆梦 2025-01-19 04:08:40

谢谢BrunoLucas-9843MughundhanRaveendran-MSFT 提供了宝贵的解释和一些解决方法。将您的建议作为答案发布以帮助其他社区成员。

  • 查看这篇文章关于为函数提取一批 1 条消息的 maxBatchSize 配置,以及在传递单个事件与有序批次时降低成本的更好方法。

有没有办法让事件中心触发器等到第一批处理完毕?

  • 一旦您发送事件并到达集线器,触发函数就会拉动该事件。还有天蓝色的函数并行性使事情变得更加复杂。

我看到 azure hub 的逻辑应用触发器可以一次拉取固定数量的事件并等待:
https: //learn.microsoft.com/en-us/azure/connectors/connectors-create-api-azure-event-hubs#trigger-polling-behavior

此外,您可以尝试在 function.json 中将基数设置为 1 并在最后进行测试。
https: //learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-event-hubs-trigger?tabs=csharp#configuration

是否可以使用Durable Function来实现顺序处理?

是的,通过利用上述建议的方法,也可以实现持久和正常的天蓝色功能。对于持久函数,您可以使用函数链接:https://learn.microsoft.com/en-us/azure/azure-functions/durable/durable-functions-overview?tabs=csharp#chaining

在持久函数中,有协调器和活动函数,如果其中一个活动函数失败,它将向协调器返回错误响应。整个实例不会失败,你将能够处理异常

Thank You BrunoLucas-9843 and MughundhanRaveendran-MSFT for your valuable explanation and few workarounds. Posting your suggestions as an answer to help other community members.

  • Check out this article regarding the configuration of maxBatchSize to pull a batch of 1 message for the function and the better way to reduce cost when passing single event vs ordered batch.

Is there a way to make the event hub trigger wait until the first batch is processed?

  • As soon you send the event and it hits the hub, the trigger function will pull that. There is also azure function parallelism that makes things more complicated.

I see that logic apps triggers for azure hub can pull a fixed number of events in one pull and wait:
https://learn.microsoft.com/en-us/azure/connectors/connectors-create-api-azure-event-hubs#trigger-polling-behavior

Additionally you can try to set the cardinality to one in the function.json and test it at your end.
https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-event-hubs-trigger?tabs=csharp#configuration

Would it be possible to achieve the sequential processing using a Durable Function?

Yes, it is possible with durable and normal azure functions as well by leveraging the above suggested methods. With durable functins, you can use functions chaining : https://learn.microsoft.com/en-us/azure/azure-functions/durable/durable-functions-overview?tabs=csharp#chaining.

In durable functions, there is orchestrator and activity functions, if one of the activity function fails it will return error response to the orchestrator. The entire instance will not fail, you will be able to handle the exception

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文