I have a service that I call. Lets call that LookupService
. I have the following line of code in my client application call that service
var resp= serviceClient.Lookup(payLoad);
Now the LookupService
has been configured by the owners of that service to not allow more than 5 concurrent service calls per client. Anymore than that and they will return HTTP 429.
I am thinking of injecting this one call to a checking method just before the call to the Lookup
method. Something to the effect of:
ICircuitBreaker cb = CircuitBreakerFactory.GetInstance(); //return a retry instance
cb.Break();
var resp= serviceClient.Lookup(payLoad);
As of right now I want to only pause and retry if the max number of concurrent calls has been hit or if service returns http code 429. I will register to an internal static variable just before each call to the Lookup method and deregister the call when the service has returned. But later on, I will want to implement another class that provides an alternate path of action or uses a fallback service. I am aware there is a retry pattern, but I feel registering each call and keeping track of calls being made to compare against the total allowed calls that the service will allow since I already know that in advance will help me preemptively break the circuit when I know it is going to fail.
Thoughts on this pattern. Workable, perfect, overkill?
Aucun commentaire:
Enregistrer un commentaire