Sumit Sawant
Sumit Sawant

Reputation: 21

How to make 10 requests/second API calls to avoid external API rate limit using Java?

I am making third party GET API calls which has per second 10 requests rate limit .How can successfully control http GET requests to avoid hitting rate limits of third party. I am using Vertx Webclient for making GET request.

Upvotes: 0

Views: 1056

Answers (1)

Rob Evans
Rob Evans

Reputation: 2874

two ways to do it with CompletableFutures:

  1. fire off 10 CompletableFutures that make your requests then send the thread to sleep for 1s - see runAsync() and supplyAsync() methods.
  2. execute 1 CompletableFuture and sleep 1/10th of a second.

If you store the CompletableFutures in a list/map (whatever works for your situation best) you can then .get() the answers later when you need to access the results.

Upvotes: 0

Related Questions