简体   繁体   English

Azure存储队列-空触发

[英]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: 有几种方法可以解决此问题:

  1. Try the new Durable Function preview ( https://azure.github.io/azure-functions-durable-extension/ ). 尝试新的耐用功能预览( https://azure.github.io/azure-functions-durable-extension/ )。 It's exactly for this situation. 正是针对这种情况。
  2. At the end of each worker queue message, figure out if it's the "last" one. 在每个工作人员队列消息的末尾,找出它是否是“最后”消息。 Ie, if you're writing unique rows to a table, just scan the table and see if it's complete. 即,如果您要向表中写入唯一行,则只需扫描表,看看它是否完整。 (this is obviously not feasible if it's a large table). (如果表很大,显然是不可行的)。
  3. Maintain a counter. 维持柜台。 Each queue message decrements the counter. 每个队列消息都会减少计数器。 The guy that decrements to 0 is the "last". 递减为0的家伙是“最后一个”。 This can be kind of a pain since there's not a great way to atomically decrement a shared counter. 这可能会很痛苦,因为没有一种自动减少共享计数器的好方法。 You could either do some etag magic, or degenerate this into case #2 by having each worker write a row to a table. 您可以做一些etag魔术,或通过让每个工作人员在表中写一行,将其简化为案例2。

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.

相关问题 如何从 Azure 存储队列触发容器应用程序? - How to trigger a Container App from Azure Storage Queue? 将 JSON 消息发送到 Azure 队列存储 - Send JSON message to Azure Queue storage 将数千条消息添加到Azure存储队列 - add thousands of messages to an Azure Storage Queue 使用 Azure 存储节点 SDK 创建队列消息时,队列触发 Azure 函数抛出异常 - Queue triggered Azure function throws exception when Queue message is created with the Azure Storage Node SDK 如何使用 Node.js 监听 azure 存储队列? - How to listen to azure storage queue with Node.js? (Azure 存储 - nodeJS)获取应用于 blob 容器和队列的 SAS 策略 - (Azure Storage - nodeJS) Getting SAS policies that are applied on blob container and queue 如何使用新的 NodeJS @azure/storage-queue 库连接到开发 Azure 存储(本地)? - How to connect to Development Azure Storage (local) with the new NodeJS @azure/storage-queue library? 错误:无法验证nodejs中的第一个证书azure队列存储createMessage - Error: unable to verify the first certificate in nodejs azure queue storage createMessage azure 队列触发器 function 从两个不同的队列中拉取 - azure queue trigger function pull from two different queues Azure:如果队列中有消息,如何触发nodejs webjob? - Azure: how to trigger a nodejs webjob when there is a message in the queue?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM