简体   繁体   中英

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). 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?

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 .

Take a look at the NextVisibleTime property:

CloudQueueMessage.NextVisibleTime

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM