Home > Software design >  Slowing down the interval of requests sent to a third party in Java Springboot?
Slowing down the interval of requests sent to a third party in Java Springboot?

Time:04-12

I have an API that I have built in Java Springboot. I need to slow down the interval of requests sent to a third party from my API. What would be a good strategy to delay multiple requests sent from a Java Springboot API so that it is sent in intervals of ms?

CodePudding user response:

Add a queue to your API and every time you receive a request don't send it to 3d party API but write it to your queue. Run your consumer for that queue from ScheduledThreadPoolExecutor with time intervals that you need.

CodePudding user response:

Please check out the Resilience4j library. This library is built to help do what you're looking to do.

Description from their website, the emphasis is mine.

Resilience4j is a lightweight fault tolerance library inspired by Netflix Hystrix, but designed for functional programming. Resilience4j provides higher-order functions (decorators) to enhance any functional interface, lambda expression or method reference with a Circuit Breaker, Rate Limiter, Retry or Bulkhead. You can stack more than one decorator on any functional interface, lambda expression or method reference. The advantage is that you have the choice to select the decorators you need and nothing else.

Guide to Resilience4j, a tutorial from Baeldung.

CodePudding user response:

The technical term for what you are looking for is Throttle.

  • Related