Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

hystrixCommand annotation - what is purpose of commandKey

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.

like image 956
j2emanue Avatar asked Feb 01 '16 20:02

j2emanue


People also ask

What is group key and command key in Hystrix?

It is used to provide metadata/configuration to particular methods. To run method as Hystrix command synchronously you need to annotate method with @HystrixCommand annotation. By default the name of command key is command method name: doTest , default group key name is class name of annotated method: HystrixService.

What is fallback method in Hystrix?

The principle is analogous to electronics: Hystrix is watching methods for failing calls to related services. If there is such a failure, it will open the circuit and forward the call to a fallback method. The library will tolerate failures up to a threshold. Beyond that, it leaves the circuit open.

What is the use of hystrix in Microservices?

Hystrix is a library that controls the interaction between microservices to provide latency and fault tolerance. Additionally, it makes sense to modify the UI to let the user know that something might not have worked as expected or would take more time.


1 Answers

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

like image 183
j2emanue Avatar answered Sep 18 '22 15:09

j2emanue