Reputation: 62559
I am using @HystrixCommand to create fallbacks in a java server.
Here is one method i have but the issue im having is im wondering am i allowed to throw in the fall back ?
@HystrixCommand(fallbackMethod = "doFallback", commandKey = "doFallbackCommand")
public Response getGraphPoints(String Id, String position) {
//do some work ... finally create a response
return a_response;
}
public Response doFallback(String Id, String position) {
//can i do this in hystrix command ? or do i really have to return a Response here?no other method will catch this throw for now
throw new ServiceUnavailableException("points could not be found");
}
The Reason im asking is that when i run this im getting the following error:
ERROR [HystrixTimer-1] [com.netflix.hystrix.contrib.javanica.command.GenericCommand] [myserver] failed to processed fallback is the method: 'doFallback'.
Upvotes: 2
Views: 6005
Reputation: 244
I had the same problem, now i understand a little how hystrix works. Hystrix does not require you to set one fallback method. Unless you want to return a default data or add business logic for that case, it is not necessary. If you throw an exception you'll "confuse" hystrix, so it will throw an HystrixRuntimeException.
I hope it helps.
Upvotes: 6