[英]Azure Storage Queue - Trigger on empty
I have a nodejs Azure Function reading for a Storage Queue which is being filled once a day. 我有一个Nodejs Azure函数读取存储队列,每天都要填充一次。 When all messages have been processed and the results are stored in a table I'd like to call a final function doing some work with the gathered data. 处理完所有消息并将结果存储在表中后,我想调用最终函数,对收集的数据进行一些处理。
What's the best way to achieve this? 实现此目标的最佳方法是什么? Can I get the remaining messages in the queue inside my nodejs bindings? 我可以在nodejs绑定内的队列中获取其余消息吗? Do I have to peek the queue through the nodejs azure sdk? 我是否必须通过nodejs azure sdk来查看队列? Can I trigger a different function when the queue runs empty? 队列为空时可以触发其他功能吗?
This is a classic "join" problem. 这是一个经典的“连接”问题。 There are a few ways to handle this: 有几种方法可以解决此问题:
The problem for your business scenario is how the function knows, that the received message is the last one from the queue. 您的业务场景的问题是函数如何知道接收到的消息是队列中的最后一条消息。 There is no direct property/method to obtain this value such as a number of visible messages in the queue. 没有直接的属性/方法来获取此值,例如队列中的许多可见消息。 Your question is interesting, you ask about the "Trigger on empty". 您的问题很有趣,您询问“空触发器”。 It not easy to implemented this kind of event in the queue comparing to the "Trigger on message". 与“消息触发”相比,在队列中实现这种事件并不容易。
However, for distributed event-driven architecture (serverless architecture) can help a pattern using a distributed Watchdog , when each business processor (function/microservice/etc.) can fire a Watchdog Event such as a ScheduleMessage, for instance, 30 seconds. 但是,对于分布式事件驱动的体系结构(无服务器体系结构),当每个业务处理器(功能/微服务/等)可以触发诸如ScheduleMessage之类的Watchdog事件(例如30秒)时,可以使用分布式Watchdog帮助一种模式。 Within this time, this Watchdog Event can be canceled or retriggered, otherwise the Watchdog Event Message will be visible in the watchdog queue/topic entity. 在这段时间内,可以取消或重新触发此看门狗事件,否则,在看门狗队列/主题实体中将看到看门狗事件消息。
Watchdog usage for your case is very straightforward. 看门狗用法非常简单。 Your QueueTrigger Function is sending a Watchdog Event message to indicate a business processing. 您的QueueTrigger函数正在发送“看门狗事件”消息以指示业务处理。 If this business process has been finished, the Watchdog is not any more retriggered and it will expire after its configured time (30s), so the Watchdog Event message is visible for its reader/subscriber. 如果此业务流程已完成,则不会再触发看门狗,并且它将在其配置的时间(30s)之后过期,因此其阅读器/订阅者可以看到“看门狗事件”消息。
The following screen snippets shows this model: 以下屏幕片段显示了此模型:
As you can see, the Watchdog is based on the Azure Service Bus Schedule/CancelScheduled messages. 如您所见,看门狗基于Azure Service Bus Schedule / CancelScheduled消息。 There is no something like RetriggerScheduledMessage, basically the retriggering scheduled message in the Service Bus Entity is done in the two steps such as CancelScheduledMessage based on its sequence number and create new one using a ScheduleMessage call (new sequence number). 没有类似RetriggerScheduledMessage的东西,基本上在服务总线实体中重新触发已调度的消息是通过两个步骤完成的,例如CancelScheduledMessage基于其序列号,并使用ScheduleMessage调用(新序列号)创建新消息 。 Handling these steps is done in the QueueTrigger Function calls as Watchdog with a Lease Blob for keeping a counter and sequence number of the ScheduleMessage. 处理这些步骤是在QueueTrigger Function调用中完成的,它作为看门狗,带有一个Lease Blob,用于保留ScheduleMessage的计数器和序列号。
It will be nice, if the Azure Service Bus Entity Queue/Topic has built-in this kind of Watchdog with a capability to retrigger already scheduled message, so we can keep the same sequence number for all business process/task. 如果Azure服务总线实体队列/主题内置了这种看门狗并具有重新触发已经安排好的消息的功能,那么这将很好,因此我们可以为所有业务流程/任务保留相同的序列号。
Anyway, if you are interesting about this Watchdog Function, I can update my answer with its implementation in C#. 无论如何,如果您对此看门狗功能感兴趣,我可以使用C#中的实现来更新我的答案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.