I am consuming 3rd party API in my service. My service is been called by azure service bus trigger function.
The problem is 3rd party API restricting 45 requests per minute(they are doing throttling and giving 429 ).
if (requestCount < 45)
{
response = await MakeRequest(json);
if (response.IsSuccessStatusCode)
{
}
}
else
{
//await Task.Delay(TimeSpan.FromMinutes(1));
Thread.Sleep(60000);
requestCount = 0;
response = await MakeRequest(json);
}
I am Trying to avoid throttling by counting the no of requests per minute, once it reach it to 45 I am delaying the process per a minute using Task. Delay.
my azure service bus trigger max concurrent calls to 4, so it is reading 4 at a time.
when it is reached above 45 then it is going to else block its delaying the process per minute,
but the problem is after delaying the process, it’s not processing the last 4 messages (45th,46th,47th & 48th).
At first turn it is processing, but once the count is reset to ‘0’ again, it’s not processing last 4 messages.
I made max concurrent calls to 1. still when it is getting processed 1 message getting left out.
I tried to use Thread.sleep also it is also giving the same error in c#.
Tech_Explorer is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.