0
votes

I'm just getting into reactive programming with Reactor 3 in Java. I want to implement a client for an http service using reactor-netty. So far, I have very basic http requests being sent perfectly. However, the service expects clients to abide by ratelimits (informing the client with traditional X-RateLimit-Limit, X-RateLimit-Remaining, etc. headers).

I want to automatically retry requests when they are ratelimited, but I'm not really sure what would be the most "idiomatic" or efficient way to do this with reactive streams. I can't simply sleep in my stream threads so what should I be looking at instead? From what I have read so far, I believe I want to look into utilizing backpressure for this task, but I'm not sure where to get started.

Sorry for the potentially broad question.

1

1 Answers

0
votes

One good way of achieving this if the rate-limited signal comes from the response is to convert that into a specific exception, propagate it via onError in your response Mono and use the retryWhen operator for a delayed retry.

In the reactor-extra artifact (groupId io.projectreactor.addons) you have a Retry utility class that can be used as a builder of Function for retryWhen.