spring-cloud-gateway
spring-cloud-gateway copied to clipboard
RetryGatewayFilterFactory should support custom exchange attribute
Describe the bug
The current implementation uses RETRY_ITERATION_KEY="retry_iteration"
as the constant attribute name for tracking the iteration in the exchange. This prevents leveraging different retry strategies for different cases - for example, for IOExceptions we want to retry up to 3 times, but for authentication issues using cached credentials we want to clear the cache, and try again 1 time.
There should be a default name, but it should be configurable which name to actually use.
It may be possible to work-around this by introducing intermediate filters which "copy" that attribute to some other attribute and vice-versa as part of the outgoing and returning chains. Alternatively, a decorator could be applied to the exchange in a preceding filter such that the RETRY_ITERATION_KEY
is mapped to some other attribute key.
The general problem is that the RetryGatewayFilterFactory does not allow creating several instances of retry filter that can be used in same processing chain. They will conflict on RETRY_ITERATION_KEY attribute (possibly on other things?). Possible solution is to allow the name of attribute to be part of RetryConfig. It must be removed from the exchange at the end of Retry filter processing.