Skip to content

Conversation

@codefromthecrypt
Copy link
Contributor

@codefromthecrypt codefromthecrypt commented Aug 17, 2016

By default, Hystrix group keys match the target name, and the target name is usually the base url. Hystrix command keys are now the same as logging keys, which are equivalent to javadoc references.

For example, for the canonical GitHub example...

  • the group key would be "https://api.github.com" and
  • the command key would be "GitHub#contributors(String,String)"

You can use HystrixFeign.Builder#setterFactory(SetterFactory) to customize this, for example, to read key mappings from configuration or annotations.

Ex.

SetterFactory commandKeyIsRequestLine = (target, method) -> {
  String groupKey = target.name();
  String commandKey = method.getAnnotation(RequestLine.class).value();
  return HystrixCommand.Setter
      .withGroupKey(HystrixCommandGroupKey.Factory.asKey(groupKey))
      .andCommandKey(HystrixCommandKey.Factory.asKey(commandKey));
};

Fixes #334
Fixes #434
Fixes #333
Obviates #444

This exposes means to customize group and command keys, for example to
use non-default conventions from configuration or custom annotation
processing.

Ex.
```java
SetterFactory commandKeyIsRequestLine = (target, method) -> {
  String groupKey = target.name();
  String commandKey = method.getAnnotation(RequestLine.class).value();
  return HystrixCommand.Setter
      .withGroupKey(HystrixCommandGroupKey.Factory.asKey(groupKey))
      .andCommandKey(HystrixCommandKey.Factory.asKey(commandKey));
};

api = HystrixFeign.builder()
                  .setterFactory(commandKeyIsRequestLine)
                  ...
```

This also makes the default's more unique to avoid clashing in Hystrix's
cache.
@ryanjbaxter
Copy link

I like this approach. Sorry for being dense about the confiKey approach, after reviewing the code, I see what you are saying now. +1 for this approach

@codefromthecrypt codefromthecrypt merged commit 177ce5e into master Aug 17, 2016
@codefromthecrypt codefromthecrypt deleted the hystrix-setterfactory branch August 17, 2016 14:52
@codefromthecrypt
Copy link
Contributor Author

sweet. I can cut a release tomorrow.

@ryanjbaxter
Copy link

Great thanks!

@spencergibb
Copy link
Contributor

Well done @adriancole!

@codefromthecrypt
Copy link
Contributor Author

codefromthecrypt commented Aug 17, 2016 via email

velo pushed a commit that referenced this pull request Oct 7, 2024
This exposes means to customize group and command keys, for example to
use non-default conventions from configuration or custom annotation
processing.

Ex.
```java
SetterFactory commandKeyIsRequestLine = (target, method) -> {
  String groupKey = target.name();
  String commandKey = method.getAnnotation(RequestLine.class).value();
  return HystrixCommand.Setter
      .withGroupKey(HystrixCommandGroupKey.Factory.asKey(groupKey))
      .andCommandKey(HystrixCommandKey.Factory.asKey(commandKey));
};

api = HystrixFeign.builder()
                  .setterFactory(commandKeyIsRequestLine)
                  ...
```

This also makes the default's more unique to avoid clashing in Hystrix's
cache.
velo pushed a commit that referenced this pull request Oct 8, 2024
This exposes means to customize group and command keys, for example to
use non-default conventions from configuration or custom annotation
processing.

Ex.
```java
SetterFactory commandKeyIsRequestLine = (target, method) -> {
  String groupKey = target.name();
  String commandKey = method.getAnnotation(RequestLine.class).value();
  return HystrixCommand.Setter
      .withGroupKey(HystrixCommandGroupKey.Factory.asKey(groupKey))
      .andCommandKey(HystrixCommandKey.Factory.asKey(commandKey));
};

api = HystrixFeign.builder()
                  .setterFactory(commandKeyIsRequestLine)
                  ...
```

This also makes the default's more unique to avoid clashing in Hystrix's
cache.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants