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.
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With