问题
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.
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?
回答1:
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. 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.
You'll need to specify a timer value, which is an NCRONTAB expression, with the following format:
{second} {minute} {hour} {day} {month} {day-of-week}
An every-1-minute expression will look like:
"0 */1 * * * *"
More info on timer triggers here.
回答2:
Take a look at the NextVisibleTime property:
CloudQueueMessage.NextVisibleTime
来源:https://stackoverflow.com/questions/58650553/can-you-rate-limit-an-azure-function-or-output-of-a-storage-queue