Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 669
wkeithvan Avatar asked Sep 21 '25 00:09

wkeithvan


1 Answers

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.

like image 137
David Makogon Avatar answered Sep 22 '25 14:09

David Makogon