Hystrix icon indicating copy to clipboard operation
Hystrix copied to clipboard

Support configuration per command group

Open fkrull opened this issue 8 years ago • 3 comments

Currently, configuration settings like command properties can only be configured either globally or per command. This makes it difficult to configure, say, command timeouts per service without manually adding configuration settings for every command or programmatically loading common settings during HystrixCommand construction.

Proposal: an additional level of properties should be supported, hystrix.command.HystrixCommandGroupKey...., which overrides the global settings, but gets overridden by command-specific settings.

fkrull avatar Jul 13 '17 15:07 fkrull

Would really like this feature as this makes maintaining configuration way more easy.

nielsvn92 avatar Jun 15 '18 08:06 nielsvn92

This functionality is still actual in 2020

Liroyd avatar Oct 13 '20 08:10 Liroyd

@Liroyd Hystrix is in maintenance mode since Nov 2018.

If it helps, I implemented hardcoded per-command-group defaults by adding them to my enum that extends HystrixCommandGroupKey. Just add a member of type HystrixCommandProperties.Setter. Then use a factory method to build your HystrixCommand instances, pass it a HystrixCommand.Setter where you can call andCommandPropertiesDefaults and pass the HystrixCommandProperties.Setter from your enum.

For a more concrete example, suppose your custom enum had class CommandGroupKey and the member had a getter getCommandPropertiesDefaults, then your factory method would look like:

    public static <T> HystrixCommand<T> create(CommandGroupKey commandGroup, String commandKey, Callable<T> callable) {
        HystrixCommand.Setter setter = HystrixCommand.Setter
                .withGroupKey(commandGroup)
                .andCommandKey(HystrixCommandKey.Factory.asKey(commandKey));
        if (commandGroup.getCommandPropertiesDefaults() != null) {
            setter = setter.andCommandPropertiesDefaults(commandGroup.getCommandPropertiesDefaults());
        }
        return new HystrixCommand<T>(setter) {
            @Override
            protected T run() throws Exception {
                return callable.call();
            }
        };
    }

This doesn't solve the problem of dynamic config but you could probably look up some documentation on Archaius and come up with a solution to that if you needed it. We ended up finding these hardcoded settings sufficient for our purposes.

Ricket avatar Oct 13 '20 16:10 Ricket