I have the HystrixFeign client and I am trying to get the cause/exception in my fallback implementation, because I would really like to know the reason for fallback so I can fix the issue why the service call has failed. But the below implementations are not getting me the cause. This works just fine and the fallback is getting called all the time. But I have no clue why. I am new to Feign and Hystrix. My application is written in java 1.6 years back and this is kind of enhancement call. So I cant go for any lambda expressions.
I have the client interface defined like below
public interface MyServiceFeignClient {
@RequestLine("POST /myService/order")
@Headers("Content-Type:application/vnd.org.company.domain.order+json;version=1.0")
ServiceResponse sendOrder(String content);
}
My FeignClientFacory is like below
public class FeignClientFactory {
private static final Logger LOG = LoggerFactory.getLogger(FeignClientFactory.class);
private String serviceUrl;
public FeignClientFactory(final String serviceUrl) {
this.serviceUrl = serviceUrl;
}
public MyServiceFeignClient newInstance() {
return HystrixFeign.builder()
.decoder(new GsonDecoder())
.target(MyServiceFeignClient.class, serviceUrl);
}
class ClientFallbackFactory implements MyServiceFeignClient, FallbackFactory<ClientFallbackFactory> {
final Throwable cause;
public ClientFallbackFactory() {
this(null);
}
ClientFallbackFactory(Throwable cause) {
this.cause = cause;
}
// note that this method is not getting called at all
@Override
public ClientFallbackFactory create(Throwable cause) {
if (cause != null) {
String errMessage = StringUtils.isNotBlank(cause.getMessage()) ? cause.getMessage() : "unknown error occured";
LOG.debug("Client fallback called for the cause : {}", errMessage);
}
return new ClientFallbackFactory(cause);
}
// everytime this method is called as fallback and the cause is just null
@Override
public ServiceResponse sendOrder(String content) {
LOG.debug("service client api fallback called");
ServiceResponse response = new ServiceResponse();
String errMessage = (cause == null ? "service client api fallback called" : cause.getMessage());
response.setErrorMessage(errMessage);
response.setResultStatus("WARN");
return response;
}
}
}