@HystrixCommand does not work properly on interface methods unless commandKey is specified
Hi,
Assume an interface and two classes implementing it
public interface YayService {
String doSomeLongWork();
}
public class CoolService implements YayService {
@HystrixCommand (
fallbackMethod = "coolFallBack",
@HystrixProperty (name = "execution.isolation.thread.timeoutInMilliseconds", value = "10000")
)
@Override
public String doSomeLongWork() {
return "Cool invoked";
}
private String coolFallBack() {
return "No cool today";
}
}
public class HotService implements YayService {
@HystrixCommand (
fallbackMethod = "hotFallBack",
@HystrixProperty (name = "execution.isolation.thread.timeoutInMilliseconds", value = "5000")
)
@Override
public String doSomeLongWork() {
return "Cool invoked";
}
private String hotFallBack() {
return "No hot today";
}
}
If one does not specify the commandKey, not only will one of the implementors will fail to timeout on their respective timeout value, but it will not find the fallback method.
The reason is that the default naming for the commandKey is the method name, which obviously will be the same for interface implementing classes. The commandKey is used to cache Commands in the HystrixPropertiesFactory (used as a map key).
Adding a key is a solution, but I would argue, that if there is a defaulting behaviour in case of interfaces it should prepend it with the name of the concrete class to avoid such conflicts.
I didn't have problems with finding fallback, but did with finding respective properties, like timeout.
In addition, using only method name as a key in internal maps looks like is a theme through all Hystrix. Because of this I have problems with metrics and their streams. Hystrix dashboard also uses method name as an main identifier.
I really do not understand why that cache identifier is relying only on a method name since this is calling for conflicts. It looks like this can simply be changed with something like threadPoolKey_groupKey_commandKey. Why only groupKey/methodName?
We haven't forced the usage of disambiguating metadata (group, threadpool) because we haven't needed it internally, and there has not been a large external demand for it.
/cc @dmgcodevil to comment on how Javanica handles disambiguating lookups for fallbacks
Actually, this is not only true for interface methods but for all methods with the same name. When I'm simultaneously calling two HystrixCommand-annotated service methods that both have set e.g. execution.isolation.thread.timeoutInMilliseconds to different values then one of the timeouts will apparently be overwritten.
Perhaps this is sth. that should at least be reflected in the documentation, isn't it?
hi all, any news? I encountered this issue using fallbackMethod, it has not recognized if used in the implemented class (@Service annotated), and in the REST controller is injected the interface UPDATE: it works only if the @HystrixCommand annotation is on the public overridden method