0

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#.

5
  • Have you tried not awaiting the delay? Commented Apr 26, 2024 at 20:52
  • 3
    Show all your code please Commented Apr 26, 2024 at 20:54
  • 1
    The fact you are making four concurrent calls and you are not processing the last four requests looks like a clue, but you need to show more of your code Commented Apr 26, 2024 at 20:56
  • You can find a RateLimiter implementation here, that allows a limited number of actions during a specified timespan. Commented Apr 27, 2024 at 4:39
  • Please provide enough code so others can better understand or reproduce the problem. Commented Apr 27, 2024 at 11:22

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.