Yaniv Cohen
Yaniv Cohen

Reputation: 379

Throttling Outgoing HTTP requests

I am using vert.x as a server to receive a search request which is then processed on the server to multiple outgoing HTTP requests to various external services.

For asynchronous behavior I have chosen to use RxJava using Vert.x native http client.

Thing is, the services I am using limit me to maximum 1 call per second.

What would be the best/simple way to throttle NIO HTTP outgoing requests?

  1. In a single server environment.
  2. In a clustered server environment.

Upvotes: 0

Views: 1804

Answers (1)

Paulo Lopes
Paulo Lopes

Reputation: 5801

In a single server a naive approach to solve your problem would be:

  1. Push the request plus an result handler to a queue
  2. Have a periodic handler that pops an element from the queue every second and executes the request
  3. Call the result handler with the result or error

In a clustered way you could extend the previous concept and wrap it on an event bus address so it would be something like:

  1. Send a message to the address with the request and setup a reply handler
  2. The service would work as on the previous explanation
  3. Instead of calling a handler the service would rely on the message reply handler to pass the result.

Upvotes: 1

Related Questions