14

Using spring's Hystrix annotation described here

I want to know what the commandKey param is. In the following context i want to know what this parameter means:

   @HystrixCommand(groupKey="UserGroup", commandKey = "GetUserByIdCommand")
public User getUserById(String id) {
    return userResource.getUserById(id);
}

notice the commandKey here is defined as GetUserByIdCommand , does this have anything to do with thread pools ? Does it mean that anything with that command key uses the same thread pool and if so does that mean that its good practice for every single method i have with a failback to have its own commandKey ?

I have about 8 classes that i want to annotate methods within. I will annotate a few of the class methods with this but im wondering how to structure the commandKeys ? should i use all the same ones , or same per class or all unique etc.

j2emanue
  • 60,549
  • 65
  • 286
  • 456
  • That key represents the HystrixCommand for monitoring, circuit-breakers, metrics publishing, caching and others. – Alfabravo Feb 01 '16 at 21:11
  • Doesn't this have to do with thread pools ? if i use unique commandKeys for all methods i annotate it will spawn many new thread pools right ? – j2emanue Feb 01 '16 at 21:24
  • 1
    If you don't provide thread pool key, then Hystrix will use group keys for controlling thread pools. If none of them is available, by default there will be only 1 thread pool, with default number of threads is 10. – Xitrum Feb 05 '16 at 10:27
  • this is the answer i was looking for but i wish you had docs to back it up or something.you can create a answer for consideration. – j2emanue Feb 05 '16 at 14:37

2 Answers2

5

finally found the answer. CommandKey is used for.

By default the name of command key is command method name: For example , getUserById but you can rename it to getUserByIdCommand

Then you can use the commandKey in hystrix commands to reference the methods. If you dont use the commandKey (its optional). then the method name is used as default. So its just to rename the command.

I found all this info here

j2emanue
  • 60,549
  • 65
  • 286
  • 456
2
  1. Does commandKey have anything to do with thread pools?

    HystrixCommand is used for monitoring, circuit-breakers, metrics publishing, caching and other such uses.

    It has nothing to do with thread pool.

    Typically each CommandGroupKey has its own thread-pool so that any one group of commands can not starve others from being able to run. A HystrixCommand can be configured with a thread-pool explicitly by injecting a ThreadPoolKey. Default CommandGroupKey is class name of annotated method.

  2. How to structure the commandKeys?

    By default the name of Commandkey is command method name, in your case, it's getUserById.

    You don't have to specify a CommandKey unless you want a different name for the command.

sofia
  • 763
  • 8
  • 11