-
Notifications
You must be signed in to change notification settings - Fork 29
Pass RetryToken value to interceptor hooks #1124
Description
The use case is the following: you're making a call to the service behind a load balancer, and when the service is overloaded (or cannot satisfy your request for whatever reason) it throws a specific error that you can handle on the client side and retry but in order to avoid hitting the same already overloaded service you can pass a header with something like "excluded instances" values so that when load balancer gets the request it can navigate it to a service instance that isn't yet overloaded.
(it is just one of the examples, but you get the gist of it)
In order to do this, I was thinking to do the following on the client side to utilize java client's retry mechanism:
- Implement a custom
RetryStrategythat based on the error can return a customRetryTokeninstance with required information in it (e.g. "instances to avoid next time") (because interceptor doesn't have access to "previous response" data) - Implement an interceptor and overload
modifyBeforeRetryLoopmethod to add required headers with values defined inRetryTokeninstance
The problem with this approach is that it seems retryToken isn't exposed to any interceptor's methods via hooks nor even via context (and a call context isn't provided to RetryStrategy).
So I was thinking that adding a retryToken to interceptors hooks might be a good solution for this? If you agree, I'm happy to make provide a PR. If not, please share your thoughts on how to approach it differently (basically modify request based on previous responses and utilize client's retry mechanism) 🙂
Thanks!