[英]Can you rate limit an Azure Function or output of a Storage Queue?
I have a Storage Queue triggered Python Azure Function that submits a job to a third-party rate-limited API (1 request/minute). I have a Storage Queue triggered Python Azure Function that submits a job to a third-party rate-limited API (1 request/minute). The queue that triggers the function will periodically receive a burst of messages, so I need a way to ensure that the function will be triggered immediately upon receiving the first message, 1 minute later on the second message, 2 minutes later on the third message, etc. until the queue is empty.
触发 function 的队列会周期性地接收突发消息,所以我需要一种方法来确保 function 在收到第一条消息后立即触发,第二条消息在 1 分钟后触发,第三条消息在 2 分钟后触发,等等,直到队列为空。
Is it possible to either rate-limit the queue or the function so I am only running the function once a minute until the queue is empty?是否可以对队列或 function 进行速率限制,所以我每分钟只运行一次 function 直到队列为空?
There's no way to rate-limit a storage queue (other than the queue naturally being rate-limited by the storage transaction rate limits, which are several orders of magnitude greater than your currently-desired rate-limit).没有办法对存储队列进行速率限制(除了队列自然受到存储事务速率限制的速率限制,这比您当前所需的速率限制大几个数量级)。
Rather than trigger your Azure function off of queue message arrival, you can set up a timer trigger for your Azure function. Rather than trigger your Azure function off of queue message arrival, you can set up a timer trigger for your Azure function. This will allow you to set up, say, a 1-minute interval on the timer, where your function can read a message and call the 3rd-party API.
这将允许您在计时器上设置 1 分钟的间隔,您的 function 可以读取消息并调用第 3 方 API。
You'll need to specify a timer value, which is an NCRONTAB expression, with the following format:您需要指定一个计时器值,它是一个 NCRONTAB 表达式,格式如下:
{second} {minute} {hour} {day} {month} {day-of-week}
An every-1-minute expression will look like:每 1 分钟一次的表达式如下所示:
"0 */1 * * * *"
Take a look at the NextVisibleTime property:看一下NextVisibleTime属性:
CloudQueueMessage.NextVisibleTime CloudQueueMessage.NextVisibleTime
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.