Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support circuit breaker configuration per Feign client #487

Open
fdw opened this issue Feb 18, 2021 · 3 comments
Open

Support circuit breaker configuration per Feign client #487

fdw opened this issue Feb 18, 2021 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@fdw
Copy link

fdw commented Feb 18, 2021

Is your feature request related to a problem? Please describe.
Currently, there seems to be no way to configure different circuit breakers for different Feign clients without listing all their methods.
I can either customize the default configuration, but then this configuration will be applied to all Feign clients. On the other hand, if I want to customize a specific configuration, I must do so for all its methods, as the circuit breaker name is <feignClientName>-<methodName>.

Describe the solution you'd like
A simple solution would be to also check for a circuit breaker called feignClientName if no more specific one is found.

An ideal solution would be similar to the other Feign configuration, i.e. I can specify a Customizer Bean in the Feign configuration, like ErrorDecoder or Retryer. This customizer would then be applied to just this Feign client.

Describe alternatives you've considered
As I said, the current alternatives would be to list all methods in a client, which is quite error-prone.

@fdw
Copy link
Author

fdw commented Mar 12, 2021

If you think this is a good idea, I might try to implement it. I just need some pointers how I would go about implementing that.

@tjuchniewicz
Copy link
Contributor

tjuchniewicz commented Aug 25, 2021

I agree with @fdw. Configuration is difficult and error-prone. In Hystrix era we used SetterFactory to customize command names. We could simply use Feign class name only or class and method. Currently we have to use:
"resilience4j.timelimiter.instances.\"[ExampleServiceClient#readData(Long, String,Integer)]\".timeoutDuration=1s",

It would be great if we could easily get the same with Spring Cloud Circuit Breaker/Resilience4j.
Maybe something similar to feign.circuitbreaker.group.enabled=true that groups all methods into one configuration for bulkhead configuration?
Another solution would be to allow to customize circuitName in FeignCircuitBreakerInvocationHandler:

class FeignCircuitBreakerInvocationHandler implements InvocationHandler {
...
   @Override
   public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
      ...
      String circuitName = Feign.configKey(target.type(), method); // allow to customize name
      ...
   }
}

My current small improvement for this issue is to display all possible circuit breaker names during app startup:

@Bean
Capability customCapability() {
      return new ConfigKeysPrintingCapability();
}

@Slf4j
public class ConfigKeysPrintingCapability implements Capability {

    @Override
    public InvocationHandlerFactory enrich(InvocationHandlerFactory invocationHandlerFactory) {
        return (target, dispatch) -> {
            Set<Method> keySet = dispatch.keySet();
            for (Method method : keySet) {
                log.info("Method key: {}", Feign.configKey(target.type(), method));
            }
            return invocationHandlerFactory.create(target, dispatch);
        };
    }
}

@tjuchniewicz
Copy link
Contributor

Fixed by #575. Now we can use CircuitBreakerNameResolver to customize circuit name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants