I have a service class, which needs to call different apis from other service. But each API have some limits, So I am using Guava's Ratelimiter to enforce the limit of the operation
@Singleton
public class A {
private final RateLimiter apiCallX;
private final int timeoutInSecondsForAPIX;
private final RateLimiter apiCallY;
private final int timeoutInSecondsForAPIY;
@Inject
public A ( @Named("apiCallXRateLimiter") apiCallX,
@Named("apiCallXRateLimiter") apiCallY,
@Named("apiCallXRateLimiter") apiCallZ,
){
this.apiCallX = apiCallX;
...
}
public ResponseX callAPIX (){
...
}
public ResponseY callAPIY (){
...
}
private modelTransformer(){ //each for request and response and for each call.
...
}
}
I am thinking to use inheritance to avoid clustering all the operation calls from this class. What are the other design patterns I could use in this scenario?
Aucun commentaire:
Enregistrer un commentaire